|
Posted by Steve on 04/18/07 13:18
well, this is the best i can offer based on what you've described...
function checkInput($value)
{
static $combination = array(
1 ,
3 ,
7 ,
8 ,
9 ,
'Table' ,
'Chair'
)
return in_array($value, $combination, true);
}
echo checkInput($var) ? 'yes' : 'no';
that's one way. and, you could build $combination from a db so that the
function scales. another way would be to write (or store and retrieve) a
regular expression or series of them:
/^[13789]|table|chair$/gi
then you'd preg_match a true or false answer from that.
hth,
me
"GarryJones" <morack@algonet.se> wrote in message
news:1176901125.935895.207100@b58g2000hsg.googlegroups.com...
|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
|
[Back to original message]
|