note 45539 added to function.in-array
| From: | lordfarquaad at notredomaine dot net | Date: | Fri, 10 Sep 2004 02:44:43 +0000 |
| Subject: | note 45539 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76369@lists.php.net to get a copy of this message | ||
This function will be faster, as it doesn't compare all elements, it stops when it founds the
good one. It also works if $haystack is not an array :-)
<?php
function in_array_multi($needle, $haystack)
{
if(!is_array($haystack)) return $needle == $haystack;
foreach($haystack as $value) if(in_array_multi($needle, $value)) return true;
return false;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45539
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45539&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45539&report=yes
Search -- http://master.php.net/manage/user-notes.php