Page 1 of 1

If a variable is one of many things

Posted: Tue May 11, 2010 9:04 pm
by carleihar
What's the easiest way to write an if statement that declares a variable must be one of many things? IE: if ($variable == red, orange, or yellow) { $variable == warm color } ? In my code I need to test if a variable is one of 6 or so things. What's the best way to code this?

Thanks!

Re: If a variable is one of many things

Posted: Tue May 11, 2010 9:20 pm
by yacahuma
from php.net

Code: Select all

$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
    echo "Got Irix";
}

Re: If a variable is one of many things

Posted: Tue May 11, 2010 9:25 pm
by carleihar
Perfect! Thanks!