Re: Suggestion for "IN()"

From: Date: Fri, 01 Oct 2004 13:05:27 +0000
Subject: Re: Suggestion for "IN()"
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-198400@lists.php.net to get a copy of this message
Jay Blanchard wrote:>
You could write a function and share it with the rest of us!
function between ($var, $min, $max) { return ($var > $min && $var < $max) ? TRUE : FALSE; } function in () { if (func_num_args() < 2) trigger_error('You must provide at least one argument for in()', E_USER_WARNING); $haystack = func_get_args(); $needle = array_shift($haystack); return in_array($needle, $haystack) ? TRUE : FALSE; } if (in('foo', 'bar', 'foobar', 'foo')) //... TRUE if (in('foo', 'bar', 'foobar', 'baz')) //... FALSE if (between(15, 10, 20)) //... TRUE I'm not sure if you want >= and <= instead in between(), but you can just change it yourself. Daniel

« previous php.general (#198400) next »