I would like to find the maximum depth of this array:
Array
(
[0] => Array
(
[children] => Array
(
[0] => Array
(
[children] => Array
(
[0] => Array
(
[children] =>
)
)
)
)
[children] => Array
(
[0] => Array
(
[children] =>
)
)
)
)
In this case it’s 3 because one of the nodes contains two children nodes.
This is the code I have been trying so far:
public static function nodeDepth($nodes) {
$node_depth = array();
foreach($nodes as $node) {
foreach($node['children'] as $childnode) {
$node_depth[] = nodeDepth($childnode)+1;
}
}
return max($node_depth);
}
Try this:
In you case with the child nodes, you will need to divide result by 2.
Greetz,
XpertEase