为什么这是真的?$test = true and false;
这个不是吗?$test = (true and false);
使用&&运算符时,两者的计算结果都为false,这也是我使用and运算符时所期望的结果。显然,除了它们具有不同的优先级之外,它们是不可互换的。
发布于 2013-05-21 23:01:07
"&&“具有比"and”更高的优先级。
// The result of the expression (true && false) is assigned to $g
// Acts like: ($g = (true && false))
$g = true && false;
// The constant true is assigned to $h and then false is ignored
// Acts like: (($h = true) and false)
$h = true and false;
var_dump($g, $h);打印false、true
发布于 2013-05-21 22:59:14
除了Precedence之外,它们都是相同的
&& > = > and,因此第一个示例等同于:($test = true) and false;
https://stackoverflow.com/questions/16673133
复制相似问题