note 87022 deleted from function.in-array by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Jun 2009 21:37:57 +0000 |
| Subject: | note 87022 deleted from function.in-array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156490@lists.php.net to get a copy of this message | ||
Note Submitter: kylefarris at gmail dot com
----
In response to the "Maybe the Fastest Recursive in_array yet?" post, I ran into a problem
using it and needed to make the <?php $needle == $stalk ?> into <?php $needle === $stalk
?> because it was returning true on items that it shouldn't have. So, just for future
reference, if someone is running into problems using this nice little php snippet, they may want to
adjust it as such:
<?php
function recursive_in_array($needle, $haystack) {
foreach ($haystack as $stalk) {
if ($needle === $stalk || (is_array($stalk) && recursive_in_array($needle, $stalk)))
{
return true;
}
}
return false;
}
?>
Thanks to the original poster, by the way.