note 93066 deleted from function.array-search by danbrown
| From: | danbrown@php.net | Date: | Fri, 21 Aug 2009 13:38:43 +0000 |
| Subject: | note 93066 deleted from function.array-search by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159750@lists.php.net to get a copy of this message | ||
Note Submitter: marcelvanbrakel at hotmail dot com
----
Here is a bugfix for frank's nice function.
The first returned value, when needle matched value[$key] was $value[id] but should not have the id
key behind it. Probably c/p from own code implentation.
<?php
function array_search_value($needle,$haystack,$arraykey=FALSE) {
foreach($haystack as $key=>$value) {
$current_key=$key;
if($arraykey){
if($needle == $value[$arraykey]){
return $value;
}
if(array_search_value($needle,$value[$arraykey]) == true) {
return $current_key;
}
}else{
if($needle == $value)
return $value;
if(array_search_value($needle,$value) == true) {
return $current_key;
}
}
}
return false;
}
?>