Skip to content
Advertisement

Is there a way to find out how “deep” a PHP array is?

A PHP array can have arrays for its elements. And those arrays can have arrays and so on and so forth. Is there a way to find out the maximum nesting that exists in a PHP array? An example would be a function that returns 1 if the initial array does not have arrays as elements, 2 if at least one element is an array, and so on.

Advertisement

Answer

This should do it:

JavaScript

Edit: Tested it very quickly and it appears to work.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement