note 91365 deleted from function.array-search by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 20:45:44 +0000 |
| Subject: | note 91365 deleted from function.array-search by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217962@lists.php.net to get a copy of this message | ||
Note Submitter: buddel
----
the recursive function by tony have a small bug. it failes when a key is 0
here is the corrected version of this helpful function:
<?php
function recursive_array_search($needle,$haystack) {
foreach($haystack as $key=>$value) {
$current_key=$key;
if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value)
!== false)) {
return $current_key;
}
}
return false;
}
?>