在if else PHP语句中使用AND / OR [英] Using AND/OR in if else PHP statement
本文介绍了在if else PHP语句中使用AND / OR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在if else PHP语句中使用'AND / OR'?它会是:
How do you use 'AND/OR' in an if else PHP statement? Would it be:
1)和
if ($status = 'clear' AND $pRent == 0) {
mysql_query("UPDATE rent
SET dNo = '$id',
status = 'clear',
colour = '#3C0'
WHERE rent.id = $id");
}
2)或
if ($status = 'clear' OR $pRent == 0) {
mysql_query("UPDATE rent
SET dNo = '$id',
status = 'clear',
colour = '#3C0'
WHERE rent.id = $id");
}
推荐答案
是的。答案是肯定的。
http://www.php.net/ manual / en / language.operators.logical.php
Yes. The answer is yes.
http://www.php.net/manual/en/language.operators.logical.php
但有两件事:
- 许多程序员喜欢
&&
和||
而不是和
和或
,但它们的工作原理相同(优先级安全)。 -
$ status ='clear'
应该是$ status =='clear'
。=
是作业,==
是比较。
- Many programmers prefer
&&
and||
instead ofand
andor
, but they work the same (safe for precedence). $status = 'clear'
should probably be$status == 'clear'
.=
is assignment,==
is comparison.
这篇关于在if else PHP语句中使用AND / OR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文