note 79534 deleted from function.array-search by felipe

From: Date: Sun, 16 Dec 2007 01:32:43 +0000
Subject: note 79534 deleted from function.array-search by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133617@lists.php.net to get a copy of this message
Note Submitter: toni dot garcia dot gutsens at gmail dot com ---- Sorry, in the previous Post, empty arrays are not unset. Add three comment code lines. 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]"); eval("\$a=\$tree{$index}[{$k}];"); // unset all elements =empty array if (count($a)==0) // is empty eval("unset(\$tree{$index}[$k]);"); // unset array } else{ if ($current!=$needle){ eval("unset(\$tree{$index}[{$k}]);"); } } } } return $tree; }

« previous php.notes (#133617) next »