Jump to content


Photo

multiple condidtions in an if statement


  • Please log in to reply
4 replies to this topic

#1 CircularStopSign

CircularStopSign
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 05 September 2006 - 10:13 PM

how would i say:

if(stuff==array[0] or array[1] or array[2]){
echo "Stuff is equal too 0,1, and 2";
}
haha sounds kind of childish but i cant find it anywhere i can only find &&

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 September 2006 - 10:15 PM

Use:
if($var == $array[0] || $var == $array[1] || $var == $array[2])
{
    echo "Stuff is equal too 0,1, and 2";
}


How ever what you'll probably want to use is in_array:
if(in_array($var, $array)
{
    echo ;    echo "$var us in the array!";
}


#3 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 05 September 2006 - 10:16 PM

if( $one || $two || $three ){
 echo "hi2u";
}
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#4 CircularStopSign

CircularStopSign
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 05 September 2006 - 10:16 PM

alright thanks... i was thinking something like that, but i wasnt sure.  i think its the same in JS right?

#5 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 05 September 2006 - 10:19 PM

Most languages that share the c-style syntax use:

|| for OR
&& for AND
! for NOT
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users