Sunday, June 30, 2019

Difference between & and && in PHP




I am confused with & and &&. I have two PHP books. One says that they are same, but the another says they are different. I thought they are same as well.



Aren't they same?


Answer



& is bitwise AND. See Bitwise Operators. Assuming you do 14 & 7:



    14 = 1110
7 = 0111
---------

14 & 7 = 0110 = 6


&& is logical AND. See Logical Operators. Consider this truth table:



 $a     $b     $a && $b
false false false
false true false
true false false
true true true


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...