note 91365 added to function.array-search
| From: | buddel at osu1 dot php dot net | Date: | Mon, 08 Jun 2009 15:13:23 +0000 |
| Subject: | note 91365 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156476@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 212.124.37.9
Probable Submitter: 195.243.107.99
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/91365
Del: integrated -- https://master.php.net/note/delete/91365/integrated
Del: useless -- https://master.php.net/note/delete/91365/useless
Del: bad code -- https://master.php.net/note/delete/91365/bad+code
Del: spam -- https://master.php.net/note/delete/91365/spam
Del: non-english -- https://master.php.net/note/delete/91365/non-english
Del: in docs -- https://master.php.net/note/delete/91365/in+docs
Del: other reasons-- https://master.php.net/note/delete/91365
Reject -- https://master.php.net/note/reject/91365
Search -- https://master.php.net/manage/user-notes.php