yeshuawatso Posted May 24, 2006 Share Posted May 24, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10321-multiple-ors/ Share on other sites More sharing options...
trq Posted May 24, 2006 Share Posted May 24, 2006 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., Quote Link to comment https://forums.phpfreaks.com/topic/10321-multiple-ors/#findComment-38476 Share on other sites More sharing options...
yeshuawatso Posted May 24, 2006 Author Share Posted May 24, 2006 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 Link to comment https://forums.phpfreaks.com/topic/10321-multiple-ors/#findComment-38519 Share on other sites More sharing options...
predator12341 Posted May 24, 2006 Share Posted May 24, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/10321-multiple-ors/#findComment-38528 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.