有关php=操作符的优先级问题
在php中,有时会遇到=操作符的优先级问题。
比如:
$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中=操作符的优先级,及其用法。
您可能感兴趣的文章:
有关php=操作符的优先级问题
PHP运算符优先级的一个例外
php运算符的优先级是什么?
php正则表达式完全教程三
python表达式是什么
php正则表达式完全教程(三)
PHP运行符优先级的面试题
PHP优先级队列的介绍(附代码)
Php入门教程之PHP 运算符用法说明
php工程师面试需要哪些方面