<?php
function searchNested($arr,$keyword){
$found = array();
foreach($arr as $item){
if($item['categorySlug']==$keyword){
$found[] = $item;
}else{
$found = array_merge($found,__FUNC__($item['categoryNested'],$keyword));
}
}
return $found;
}
var_dump(searchNested(array(array
(
'categoryName' => 'Moto',
'categoryTitle' => 'Moto',
'categorySlug' => 'moto-and-tech',
'categoryAttr' => array
(
0 => 'test1',
1 => 'test2',
2 => 'test3',
3 => 'test4'
),
'categoryNested' => array
(
0 => array
(
'categoryName' => 'anything',
'categoryTitle' => 'anything',
'categorySlug' => 'anything',
'categoryAttr' => array
(
0 => 'test1',
1 => 'test1',
2 => 'test1',
3 => 'test1'
),
'categoryNested' => array()
),
1 => array
(
'categoryName' => 'any',
'categoryTitle' => 'any',
'categorySlug' => 'any',
'categoryAttr' => array
(
0 => 'test1',
1 => 'test1',
2 => 'test1',
3 => 'test1'
),
'categoryNested' => array()
)))),'any'));
preferences:
58.59 ms | 402 KiB | 5 Q