Page 1 of 1

Compare a var to two or more values.

Posted: Fri May 18, 2007 12:28 am
by JellyFish
How do I compare $var to two or more values?

E.g:

Code: Select all

if ($var != "this" && "this")
This obviously doesn't work or then I wouldn't be asking this question. :D

So how do I do this:

Code: Select all

if (($var != "this") && ($var != "that"))
Only in a more compact way, so to speak.

Posted: Fri May 18, 2007 2:27 am
by volka
e.g.

Code: Select all

if ( !in_array($var, array('x','y','z')) )

Posted: Fri May 18, 2007 9:50 pm
by JellyFish
Thanks man. It works like a charm. :D

If there are any other suggestions that might be shorter this topic is still open.