I want to be able to know the level of an array as it is being built.
The code loops through a bunch of directories to create a massive multi-dimensional array.
As the array is being created, I want to know how deep in the array I am.
1 2 3 4
---------------------
Root
A
A2
A3
A4
A4a
B
B2
B3
C
D
E
E2
E2a
E3
In the example above, the root directory is in level 1. All single uppercase letters are in level 2. All uppercase letters with a number are in level 3. All uppercase letters with a number and a lowercase letter are in level 4.
As I’m building the array, is there any way for me to know which level I’m in? The array is being created with a recursive function.
This is a PHP question.
One quick an easy answer is to simply add a “depth” parameter to your function and increment it when the function calls itself.