Jump to content

Archived

This topic is now archived and is closed to further replies.

yeshuawatso

Multiple ors

Recommended Posts

Does PHP support multiple "ors" for instance if(something != somthing or somthing or something or something){
}

I know my other option is using else ifs, but I want to see if I could get this in one line of code.

THanks,
Yeshua

Share this post


Link to post
Share on other sites
Yes.
[code]
if ($a == $b || $c == $d || $e == $f) { echo "an expression returned true" };
[/code]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I know my other option is using else ifs,[/quote]
Or's aren't quite the same as else() if() in that they will only ever be able to execute the same code based on a condition.,

Share this post


Link to post
Share on other sites
Ok, this works for different variables, but does the same function work for the same variable?

[code]if($a == $b || $a == $c ||etc.){return true or false or whatever I need it to do here.}[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=376620:date=May 24 2006, 11:22 AM:name=Yeshua Watson)--][div class=\'quotetop\']QUOTE(Yeshua Watson @ May 24 2006, 11:22 AM) [snapback]376620[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Ok, this works for different variables, but does the same function work for the same variable?

[code]if($a == $b || $a == $c ||etc.){return true or false or whatever I need it to do here.}[/code]
[/quote]

yes that will work but make sure you get you logic right or you will run into errors

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.