How to quickly determine the depth of an array is as follows:
The code is as follows:
Array (
Array (
Array (1, 3, 4 ),
Array (
Array (
1, 2, 3
)
)
),
Array (
Array (1, 2 ),
Array (1)
)
)
The depth of this array is 5, so how to quickly determine the depth of an array.
(PS: T good php q buckle: 276167802, verification: csl)
In fact, only the above answers should be sorted again. Here is a simple deep computing function:
The code is as follows:
Function array_depth ($ 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;
}
$ Array = array ("11"), array (), array ("5", "6"), "7 ", "8"), array ("5", "6"), "7", "8"), "9", "10 ");
Echo array_depth ($ array );
?>
I hope this article will be helpful to the majority of php developers. thank you for reading this article.