Page 1 of 1
PHP code for AND...simple but I forgot
Posted: Thu Nov 04, 2004 10:55 am
by ljCharlie
Can anyone tell me wha the AND is for PHP code? When lookup this code on php.com site, it said that & means AND; however, many of my code I used && for AND. Will the following both workd?
Code: Select all
if($a == $b & $b==$c){
//do something here
}
//or this way
if($a == $b && $b==$c){
//do something here
}
Will both of these work the same way? The php.com site didn't show the && at all.
Help is appreciated.
ljCharlie
Posted: Thu Nov 04, 2004 11:02 am
by The Monkey
&& is correct, my understanding is that one & is not, however, I personally prefer to use AND (or even the lowercase 'and') because it is immediately clear what the operative is.
Logical Operators

- Monkey
Posted: Thu Nov 04, 2004 11:08 am
by ljCharlie
Many thanks for your help. Are you saying I can use the word "and" and "or" for && and ||?
Isn't this,
http://www.php.net/manual/en/language.o ... itwise.php, the correct page?
ljCharlie
Posted: Thu Nov 04, 2004 1:05 pm
by rehfeld
you really should understand the difference between
AND (or) &&
before you start using AND/OR
&& (and) || have a higher precedence over
AND (and) OR
its likely you will create bugs if you use them and dont understand them fully
& (and) | are bitwise operators, most likely not what you want.
http://php.net/operators (view the comments too)
Posted: Fri Nov 05, 2004 9:26 am
by ljCharlie
Thanks!
ljCharlie