note 79529 added to function.array-search
| From: | toni dot garcia dot gutsens at gmail dot com | Date: | Sun, 02 Dec 2007 12:38:39 +0000 |
| Subject: | note 79529 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132734@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 80.64.47.13
Probable Submitter: 87.219.85.252
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/79529
Del: integrated -- https://master.php.net/note/delete/79529/integrated
Del: useless -- https://master.php.net/note/delete/79529/useless
Del: bad code -- https://master.php.net/note/delete/79529/bad+code
Del: spam -- https://master.php.net/note/delete/79529/spam
Del: non-english -- https://master.php.net/note/delete/79529/non-english
Del: in docs -- https://master.php.net/note/delete/79529/in+docs
Del: other reasons-- https://master.php.net/note/delete/79529
Reject -- https://master.php.net/note/reject/79529
Search -- https://master.php.net/manage/user-notes.php