php=操作符的优先级问题

 

$a = '1';
$b = '2';
$c = '3';
($a == $b || !$c = '4' || $c = '5') && $c = '6';
echo $c;

!$c = '4' || $c = '5' 表达式等价于!$c = ('4' || $c = '5')并等价于false,PHP手册有一句话:

Although = has a lower precedence than most other operators, PHP will still allow expressions similar to the following: if (!$a = foo()), in which case the return value of foo() is put into $a.

因此结果为1

 

你可能感兴趣的:(PHP)