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.

 

目录
相关文章
|
5月前
|
Java
“a == b” 和 “a.equals(b)” 的区别
【8月更文挑战第22天】
78 0
|
7月前
|
存储 Java
equals与==区别
equals与==区别
52 0
|
8月前
|
JavaScript 前端开发 安全
== 和 ===什么区别呀?
== 和 ===什么区别呀?
134 0
equals 和 == 的区别?
equals 和 == 的区别?
98 0
|
8月前
! [ ] == ! [ ] 和 ! [ ] == [ ] 结果是什么? 为什么?
! [ ] == ! [ ] 和 ! [ ] == [ ] 结果是什么? 为什么?
49 0
|
JavaScript 前端开发
== 和 ===区别,分别在什么情况使用
== 和 ===区别,分别在什么情况使用
85 1
|
Java
==和equals()
==和equals()
95 0
equals和 == 的区别
equals和 == 的区别
90 0

热门文章

最新文章