论坛首页 编程语言技术论坛

php=操作符的优先级问题

浏览 1124 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2013-09-06  

 

$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

 

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics