HELP! Using AND or OR

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
Hagar
Forum Newbie
Posts: 18
Joined: Mon May 20, 2002 3:28 am
Location: Johannesburg, South Africa

HELP! Using AND or OR

Post by Hagar »

How would I use AND or OR
ie.

Code: Select all

if($x != $y or $y <= $z)&#123;
bla bla bla........

&#125;
or Must I Use

Code: Select all

if($x != $y || $y <= $z)&#123;
bla bla bla........
&#125;
like in C++

and the same with AND

Code: Select all

if($x != $y and $y <= $z)&#123;
bla bla bla........
&#125;
or Must I Use

Code: Select all

if($x != $y && $y <= $z)&#123;
bla bla bla........
&#125;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can use either, depending on how you want the precendence to work.. check the documentation here to read about their differences..


notice how &&, ||, and ^ are processed before assignment operators. Judging by the logic you have used in your examples, the first ones are the ones (and/or) would perform as you expect it would. Whereas the ||/&& ones will likely not.
Post Reply