如果您不知道深度,可以执行以下操作,其中使用了 RecursiveIteratorIterator 和 RecursiveArrayIterator:
<?php
/*******************************
* array_multi_search
*
* @array array to be searched
* @input search string
*
* @return array(s) that match
******************************/
function array_multi_search($array, $input){
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
foreach($iterator as $id => $sub){
$subArray = $iterator->getSubIterator();
if(@strstr(strtolower($sub), strtolower($input))){
$subArray = iterator_to_array($subArray);
$outputArray[] = array_merge($subArray, array('Matched' => $id));
}
}
return $outputArray;
}