3v4l.org

run code in 300+ PHP versions simultaneously
<?php function searchNested($arr,$keyword){ $found = array(); foreach($arr as $item){ if($item['categorySlug']==$keyword){ $found[] = $item; }else{ $found = array_merge($found,__FUNC__($array,$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() ))))));

preferences:
60.36 ms | 402 KiB | 5 Q