Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's the difference between & and &&

Coding

What's the difference between & and &&

by  AnakinPt  Posted    (Edited  )
in the following piece of code:

$a=10 ; //(1010b)
$b = 0; // (0000b)

if ($a & $b)

is different from

if ($a && $b)

The first one is true and the second if false.

When we use only one & it means bit-by-bit and operation, so $a & $b=10 (1010b), while when you use && it means and operator of clauses and in this case $a && $b = 0, cause $b=0.

Beware of the signs. This FAQ is also valid for the or operator ('|').

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top