or ||

简介: Is $z TRUE or FALSE? In this case, $z will be FALSE because the above code is equivalent to rather than as might be expected - because the ...
<?php
$x=TRUE;
$y=FALSE;
$z=$y OR $x;
?>

Is $z TRUE or FALSE?

In this case, $z will be FALSE because the above code is equivalent to <?php ($z=$y) OR $x ?> rather than <?php $z=($y OR $x) ?> as might be expected - because the OR operator has lower precedence than assignment operators.

On the other hand, after this code sequence:
<?php
$x=TRUE;
$y=FALSE;
$z=$y || $x;
?>

$z will be TRUE, as expected, because the || operator has higher precedence than assignment:  The code is equivalent to $z=($y OR $x).

This is why you should NEVER use the OR operator without explicit parentheses around the expression where it is being used.

 

目录
相关文章
|
4月前
|
JavaScript 前端开发 安全
== 和 ===什么区别呀?
== 和 ===什么区别呀?
|
4月前
! [ ] == ! [ ] 和 ! [ ] == [ ] 结果是什么? 为什么?
! [ ] == ! [ ] 和 ! [ ] == [ ] 结果是什么? 为什么?
31 0
|
4月前
|
JavaScript 前端开发
为什么typeof null == 'object' 为true?
为什么typeof null == 'object' 为true?
25 0
|
JavaScript 前端开发
== 和 ===区别,分别在什么情况使用
== 和 ===区别,分别在什么情况使用
64 1
|
Java
==和equals()
==和equals()
65 0
|
Python
a is b 为 True,a == b 一定为 True 吗?
a is b 为 True,a == b 一定为 True 吗?
104 0
|
JavaScript
js 如何if( a== 1 && a == 2 && a==3)
js 如何if( a== 1 && a == 2 && a==3)
129 0
|
存储
什么时候 a == 1 && a == 2 && a == 3 为 true?
什么时候 a == 1 && a == 2 && a == 3 为 true?
118 0
什么时候 a == 1 && a == 2 && a == 3 为 true?