If a variable is one of many things

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
carleihar
Forum Commoner
Posts: 36
Joined: Fri Nov 13, 2009 5:59 pm

If a variable is one of many things

Post 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!
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: If a variable is one of many things

Post by yacahuma »

from php.net

Code: Select all

$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
    echo "Got Irix";
}
carleihar
Forum Commoner
Posts: 36
Joined: Fri Nov 13, 2009 5:59 pm

Re: If a variable is one of many things

Post by carleihar »

Perfect! Thanks!
Post Reply