我尝试在PHP脚本中的IF语句中使用运算符AND,OR,如下所示:
if($user[id]=='1' AND (($_GET['f']=='f-ppas') || ($_GET['f']=='f-kua'))){
.....
}
但结果是错误的。谁能帮我?
将AND
更改为&&
if($user['id']=='1' && (($_GET['f']=='f-ppas') || ($_GET['f']=='f-kua'))){
.....
}
AND
运算符存在一些优先级问题。
$this = true;
$that = false;
$truthiness = $this and $that;
上面的$truthiness
值为 true
。为什么? =
的优先级高于 and。添加括号以显示隐式顺序使这一点更加清晰:
($truthiness = $this) and $that
如果在第一个代码示例中使用 &&
而不是 and
,它将按预期工作并且为 false。
参考:"AND"与"&&"作为运算符