我有一個數組解析函數,查找值中的部分單詞匹配。我如何使它遞歸,因此適用於多維數組?如何使數組查找函數遞歸
function array_find($needle, array $haystack)
{
foreach ($haystack as $key => $value) {
if (false !== stripos($needle, $value)) {
return $key;
}
}
return false;
}
陣列我需要通過
array(
[0] =>
array(
['text'] =>'some text A'
['id'] =>'some int 1'
)
[1] =>
array(
['text'] =>'some text B'
['id'] =>'some int 2'
)
[2] =>
array(
['text'] =>'some text C'
['id'] =>'some int 3'
)
[3] =>
array(
['text'] =>'some text D'
['id'] =>'some int 4'
)
etc..
你可以使用[RecursiveFilterIterator(http://www.php.net/manual/en/class.recursivefilteriterator.php)的實現。 – Wrikken
這個問題有幫助嗎? http://stackoverflow.com/questions/2504685/php-find-parent-key-of-array – afuzzyllama
@afuzzyllama,不 - 我有鑰匙。我需要檢查任何值中是否存在部分詞匹配,然後獲取關聯鍵=>值。這發現整個值匹配,然後給你的父鍵,我不是真的需要。 – Chamilyan