Posted by Geoff Berrow on 12/20/06 11:12
Message-ID: <15270vgkskofw$.ex7bxqbswi4v.dlg@40tude.net> from Els
contained the following:
>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)"
I've just started playing round with regexp so this may not be optimal
$pattern = '/(?<![0-9])([1-4]|17|30)(?![0-9])/';
if(preg_match($pattern, $a)>0){
//do stuff
}
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Navigation:
[Reply to this message]
|