note 93066 added to function.array-search
| From: | marcelvanbrakel at hotmail dot com | Date: | Fri, 21 Aug 2009 13:37:10 +0000 |
| Subject: | note 93066 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159748@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 2001:1af8:fe06:0:4daf:d373:d573:7162
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/93066
Del: integrated -- https://master.php.net/note/delete/93066/integrated
Del: useless -- https://master.php.net/note/delete/93066/useless
Del: bad code -- https://master.php.net/note/delete/93066/bad+code
Del: spam -- https://master.php.net/note/delete/93066/spam
Del: non-english -- https://master.php.net/note/delete/93066/non-english
Del: in docs -- https://master.php.net/note/delete/93066/in+docs
Del: other reasons-- https://master.php.net/note/delete/93066
Reject -- https://master.php.net/note/reject/93066
Search -- https://master.php.net/manage/user-notes.php