Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

& 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...