note 79327 modified in function.array-search by danbrown
| From: | danbrown@php.net | Date: | Wed, 29 Apr 2009 12:57:26 +0000 |
| Subject: | note 79327 modified in function.array-search by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153973@lists.php.net to get a copy of this message | ||
<?php
/*Another recursive array_search that works better for me
* Returns all the keys to all the needles found
*and put them in an array.
*/
function array_search_recursive($needle, $haystack, $a=0, $nodes_temp=array()){
global $nodes_found;
$a++;
foreach ($haystack as $key1=>$value1) {
$nodes_temp[$a] = $key1;
if (is_array($value1)){
array_search_recursive($needle, $value1, $a, $nodes_temp);
}
else if ($value1 === $needle){
$nodes_found[] = $nodes_temp;
}
}
return $nodes_found;
}
?>
--was--
<?php
/*Erratum from my previous post.
* Returns all the keys to all the needles found
*and put them in an array.
*/
function array_search_recursive($needle, $haystack, $a=0, $nodes_temp=array()){
global $nodes_found;
$a++;
foreach ($haystack as $key1=>$value1) {
$nodes_temp[$a] = $key1;
if (is_array($value1)){
array_search_recursive($needle, $value1, $a, $nodes_temp);
}
else if ($value1 === $needle){
$nodes_found[] = $nodes_temp;
}
}
return $nodes_found;
}
?>
http://php.net/manual/en/function.array-search.php