Posted by Mitul on 04/18/07 13:18
On Apr 18, 5:58 pm, GarryJones <mor...@algonet.se> 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
Hello,
If you have array of all possible 170 values then you can try with
in_array function. If you don't have array then prepare it and then
check it.
[Back to original message]
|