I have the following array
Array
(
[id] => 3
[parent] => Array
(
[id] => 2
[parent] => Array
(
[id] => 1
[parent] => 0
[name] => parent
)
[name] => child
)
[name] => grandchild
)
I want to dive very deep, like the following
Array
(
[id] => 1
[parent] => 0
[name] => parent
)
Max depth following array is unlimited, any idea ?
Can i dive(1) to get array grandchild, dive(2) to get array child, dive(3) to get array parent ? i following this function to calculate the depth of the array
function array_depth(array $array) {
$max_depth = 1;
foreach ($array as $value) {
if (is_array($value)) {
$depth = array_depth($value) + 1;
if ($depth > $max_depth) {
$max_depth = $depth;
}
}
}
return $max_depth;
}