|
Posted by Tyno Gendo on 04/18/07 13:14
GarryJones wrote:
> I need to test for one of several values. Can I include these in a
> single "if" statement
>
> I tried using OR but it does not work. In the actual file I need to
> check if a supplied user input meets one of about 170 possible code
> combinations.
>
> This does not work
>
> if ($var == 1 OR 3 OR 7 OR 8 OR 9 OR "Table" OR "Chair"){
> echo 'yes';
> } else {
> echo 'no';
> }
>
> A long winded way to do it and the only way I know how to use OR is...
>
> if ($var == 1 || $var == 3 || $var == 7 || $var == 7 || $var == 9 ||
> $var == "Table" || $var == "Chair")
> ...etc
>
> But I would like to just list the values (and not the $var == for
> every possible condition
>
> Garry Jones
> Sweden
>
if ( in_array( $var, array( 1, 3, 7, 9) ) {
// do something
}
Navigation:
[Reply to this message]
|