Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$a = true and false; //true $b = true && false; //false $c = (true and false); //false $d = (true && false); //false
为什么给出案例'a'为真?
我认为 and 和 && 具有相同的优先级,但他们没有。
如文档中所述,这是预期的
// The constant true is assigned to $h and then false is ignored // Acts like: (($h = true) and false) $h = true and false;
http://php.net/manual/en/language.operators.logical.php
将常量 true 分配给 $a,然后忽略 false。这都是关于运算符优先级的