Jump to content


Photo

Multiple ors


  • Please log in to reply
3 replies to this topic

#1 yeshuawatso

yeshuawatso
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 24 May 2006 - 05:26 AM

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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 24 May 2006 - 05:35 AM

Yes.
if ($a == $b || $c == $d || $e == $f) { echo "an expression returned true" };
[!--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.,

#3 yeshuawatso

yeshuawatso
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 24 May 2006 - 10:22 AM

Ok, this works for different variables, but does the same function work for the same variable?

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


#4 predator12341

predator12341
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts
  • LocationCheshunt, Hertfordshire, England

Posted 24 May 2006 - 11:28 AM

[!--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) View Post[/div][div class=\'quotemain\'][!--quotec--]
Ok, this works for different variables, but does the same function work for the same variable?

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

yes that will work but make sure you get you logic right or you will run into errors
[a href="http://www.sloganizer.net/en/" target="_blank"][/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users