I need a method to traverse a multidimensional array in PHP without using function calls itself.
Basically I have an array like this:
$data = array(
'hoge' => 123,
'foo' => 456,
'bar' => 789,
'aaa' => array(
'abc' => 111,
'bcd' => 222,
'cde' => 333
),
'bbb' => array(
'def' => array(
'efg' => 'hoge'
)
),
'stacks' => array(
'a',
'b'=> array('qwe' => 111,
'asd' => 222,
'args' => array('1',
'2',
'3')),
'c'
)
);
Generally you use a function like this:
function get_array_elems($arrResult, $where="array"){
while(list($key,$value)=each($arrResult)){
if (is_array($value)){
get_array_elems($value, $where."[$key]");
}
} else {
...anything
}
}
get_array_elems($arrResult);
I can not use this method because i have to write this method in a PHP function and it can not write a function in another function.
Can it be done using an iterative method such as while, foreach, array_walk_recursive etc.?