I have a menu array, it's a multidimensional array, and I want to do some thing with every single item, so I tried array_walk_recursive. Here is the menu:
$menu = array(
array(
'name'=>'a',
'url'=>'b',
),
array(
'name'=>'c',
'url'=>'d',
'children'=>array(
array(
'name'=>'e',
'url'=>'f'
)
)
)
);
But array_walk_recursive only let me handle every single element, but not array.
array_walk_recursive($menu, function(&$item){
var_dump($item);//return a;b;c;d;e;f;g
});
What I want is like this:
array_walk_recursive_with_array($menu, function(&$item){
var_dump($item);//return array('name'=>'a','url'=>'b');a;b;array('name'=>'c',...);c;d;...
if(is_array($item) && isset($item['name'])){
// I want to do something with the item.
}
})
Is there any PHP native function implementation?
array_walk_recursiveis to modify array. how would you want your$menuto be afterarray_walk_recursiveis executed.