I have a such array
<?php
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
)
)
)
)
)
)
),
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
)
)
)
),
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
array(
'CHILDRENS' => array(
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
I would like to know how to get the maxium deep of this array. I tried this :
Array PHP. How to get deep of element in array
and
Is there a way to find out how "deep" a PHP array is?
It that last case, it return only first array depth
Thanks for help.
public function array_depth(array $array, $current_depth = 0) { global $depth; if( $array ) { foreach ( $array as $key => $value ) { // var_dump( $key ); if ( is_array( @$value[ 'CHILDRENS' ] ) ) { $this->array_depth( $value[ 'CHILDRENS' ], $current_depth + 1 ); } } } else { if( intval( $depth ) < $current_depth ) { $depth = $current_depth; } } return intval( $depth ); }
– Blair Jersyer Apr 20 '16 at 14:28