Friday, July 31, 2009

How can I compare in PHP if a list of values are equal to a variable?

I need to simplify multiple comparisons in an if statement. For example instead of:





if ($variable == "First" || $variable == "Second" || $variable == "Third") ...





perhaps a biult-in function like this:





if (some_function($variable, "Fisrt", "Second", "Third")) ...





Is there any function to accomplish this?

How can I compare in PHP if a list of values are equal to a variable?
look up a function called in_array. bascially you create an array of all valid values and then run the in_array function


No comments:

Post a Comment