0

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.

Community
  • 1
  • 1
  • Which of the many "last case" solutions exactly have you tried? – deceze Apr 20 '16 at 13:23
  • The provided solution http://stackoverflow.com/a/262944/4028339 doesn't work. This function count all the depth, i want to get count the array levels. – Blair Jersyer Apr 20 '16 at 13:44
  • I finally found a solution by myself. 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

0 Answers0