Re: Function suggestion
| From: | Andrei Zmievski | Date: | Mon, 10 Jul 2000 14:00:23 +0000 |
| Subject: | Re: Function suggestion | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-24076@lists.php.net to get a copy of this message | ||
On Mon, 10 Jul 2000, Richard Heyes wrote:
> More of a language construct really, the IN() function that MySQL has,
> as a shortcut for multiple ORs. Like so:
>
> if($var IN('compare1', 'compare2', 'compare3')){
> ...blah...
> }
>
> Here's my (somewhat limited) php version of it...
>
> function in($compare, $options, $seperator = ','){
> $opt_array = explode($seperator, $options);
> for($i=0; $i<count($opt_array); $i++) if($compare == $opt_array[$i])
> return TRUE;
> return FALSE;
> }
>
> Take care!
Already taken care of:
if (in_array($var, $array)) {
// it's there
}
-Andrei
"Later in this talk, I intend to define
the universe and give three examples." -- Larry Wall