PHP code for AND...simple but I forgot

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

PHP code for AND...simple but I forgot

Post 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
The Monkey
Forum Contributor
Posts: 168
Joined: Tue Mar 09, 2004 9:05 am
Location: Arkansas, USA

Post 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

:D - Monkey
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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)
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Thanks!

ljCharlie
Post Reply