Difference between & and && in PHP

& 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

AND operation:

& -> will do the bitwise AND operation , it just doing operation based on
the bit values.
&& -> It will do logical AND operation. It is just the check the values is
true or false. Based on the boolean value , it will evaluation the
expression

Leave a Reply

Your email address will not be published. Required fields are marked *