note 38983 deleted from function.in-array by irchtml
| From: | irchtml@php.net | Date: | Wed, 25 Feb 2004 20:00:55 +0000 |
| Subject: | note 38983 deleted from function.in-array by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65752@lists.php.net to get a copy of this message | ||
Note Submitter: Frank Sträter
----
I combined some ideas in previous notes to this elegant function for checking against values in
multi-dimensional arrays.
It also solves the bug mentioned by Raphinou, which is 'If the haystack contains the boolean
true, in_array returns true!!'.
bool in_array_multi ( mixed needle, array haystack )
<?php
function in_array_multi($needle, $haystack) {
static $return = false;
if (!is_array($haystack)) return false;
while (list($key, $value) = each($haystack)) {
if ($value == $needle) {
$return = true;
break;
}
if (is_array($value))
in_array_multi($needle, $value);
}
return $return;
}
?>