|
Posted by Els on 12/20/06 10:07
KoopaJah wrote:
> Els wrote :
>> I'm just looking for a way to write the following in a shorter way:
>> if ($a == 1 || $a == 2 || $a == 3 || $a == 4 || $a == 17 || $a == 30)
>>
>> Something that equates to "if $a == one of ((1 - 4), 17, 30)"
>
> A simple possibility could be to declare an array with all the values
> that $a cannot take and use the in_array() function. Something like this:
>
> $forbiddenValues = array(1,2,3,4,17,30);
> if (in_array($a, $forbiddenValues ))
> {
> // some code
> }
Thanks, works perfect. (albeit it's not about forbidden values, but
rather accepted values ;-) )
> But it does not allow you to define something like "all values between 1
> and 4".
That's a shame, but it's still better than what I had.
Thanks!
--
Els http://locusmeus.com/
Navigation:
[Reply to this message]
|