开发者

Php: What is the difference between | and || operator [duplicate]

开发者 https://www.devze.com 2023-02-18 20:09 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicates: Reference - What does this symbol mean in PHP?
This question already has answers here: Closed 11 years ago.

Possible Duplicates:

Reference - What does this symbol mean in PHP?

What is the difference between the | and || operators?

Just bumped into this line of code, and I was wondering what is the di开发者_如何转开发fference between these two case:

The person who did this do not remember what was the meaning, but it was important.

...
if ($condition1 | $condition2) {
...
...
if ($condition1 || $condition2) {
...


| = bitwise or

|| = boolean or


| is a bitwise or, || is a logical or. | operates on binary values whereas || operates on boolean ones.

E.g. 5 | 3 is 0101 OR 0011 which is 0111 which is 7, whereas True || False is True and False || False is False.


| is the bitwise-OR-operator while || is the logical-OR-operator.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号