在 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
不过有两点:
- 许多程序员更喜欢
&&
和||
而不是and
和or
,但它们有效相同(安全优先). $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屋!
查看全文