清风听雨 发表于 2017-3-29 10:19:53

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
页: [1]
查看完整版本: php=操作符的优先级问题