“||”之间有什么区别和“或”,我尝试在PHP中这样做
$a = false || true;
$b = false or true;
var_dump($a);
var_dump($b);
你显然认为true
的{{1}}和$a
的结果为true
,但我得到的结果是:
$b
答案 0 :(得分:6)
“||”优先级高于“或”
示例(来自PHP文档)
<?php
// "||" has a greater precedence than "or"
$e = false || true; // $e will be assigned to (false || true) which is true
$f = false or true; // $f will be assigned to false
var_dump($e, $f);
?>
在此处阅读更多内容:http://php.net/manual/en/language.operators.logical.php