note 79529 deleted from function.array-search by danbrown
| From: | danbrown@php.net | Date: | Wed, 29 Apr 2009 12:56:53 +0000 |
| Subject: | note 79529 deleted from function.array-search by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153972@lists.php.net to get a copy of this message | ||
Note Submitter: toni dot garcia dot gutsens at gmail dot com
----
Make a recursive search on array and return the matches elements in the same structure than the
original array:
function array_search_recursive($needle, $haystack,&$tree=Array(),$index=""){
if (is_array($haystack)){
if (count($tree)==0) $tree=array_merge(Array(),$haystack);
foreach($haystack as $k=>$current){
if (is_array($current)){
array_search_recursive($needle,$current,$tree,$index."[$k]");
}
else{
if ($current!=$needle){
eval("unset(\$tree{$index}[{$k}]);");
}
}
}
}
return $tree;
}