note 80692 modified in function.array-search by danbrown
| From: | danbrown@php.net | Date: | Wed, 29 Apr 2009 12:55:11 +0000 |
| Subject: | note 80692 modified in function.array-search by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153967@lists.php.net to get a copy of this message | ||
MultiArray find function.
After some time unsuccessful looking for algorithm to find a string in multidimensional array I
wrote one:
<?php
function multidimArrayLocate($array, $text){
foreach($array as $key => $arrayValue){
if (is_array($arrayValue)){
if ($key == $text) $arrayResult[$key] = $arrayValue;
$temp[$key] = multidimArrayLocate($arrayValue, $text);
if ($temp[$key]) $arrayResult[$key] = $temp[$key];
}
else{
if ($key == $text) $arrayResult[$key] = $arrayValue;
}
}
return $arrayResult;
}
?>
--was--
MultiArray find function.
After some time unsuccessful looking for algorithm to find a string in multidimensional array I
wrote one:
function multidimArrayLocate($array, $text){
foreach($array as $key => $arrayValue){
if (is_array($arrayValue)){
if ($key == $text) $arrayResult[$key] = $arrayValue;
$temp[$key] = multidimArrayLocate($arrayValue, $text);
if ($temp[$key]) $arrayResult[$key] = $temp[$key];
}
else{
if ($key == $text) $arrayResult[$key] = $arrayValue;
}
}
return $arrayResult;
}
http://php.net/manual/en/function.array-search.php