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.

 

目录
相关文章
|
6月前
|
JavaScript 前端开发 安全
== 和 ===什么区别呀?
== 和 ===什么区别呀?
110 0
|
6月前
! [ ] == ! [ ] 和 ! [ ] == [ ] 结果是什么? 为什么?
! [ ] == ! [ ] 和 ! [ ] == [ ] 结果是什么? 为什么?
41 0
|
JavaScript 前端开发
== 和 ===区别,分别在什么情况使用
== 和 ===区别,分别在什么情况使用
74 1
|
Java
==和equals()
==和equals()
73 0
equals和 == 的区别
equals和 == 的区别
78 0
|
存储
什么时候 a == 1 && a == 2 && a == 3 为 true?
什么时候 a == 1 && a == 2 && a == 3 为 true?
132 0
什么时候 a == 1 && a == 2 && a == 3 为 true?
a==b,b==c都为true,那a==c一定为true吗???
a==b,b==c都为true,那a==c一定为true吗???
a==b,b==c都为true,那a==c一定为true吗???
|
存储 Java
今天我们来解决0.1d+0.2d==0.3d是false的问题!
今天我们来解决0.1d+0.2d==0.3d是false的问题!
今天我们来解决0.1d+0.2d==0.3d是false的问题!