I am building a directory tree via array. I need to find a way to use a GET variable to navigate the tree. Here's an example:
My array would be laid out as such
$list = array(2) {
[0] => array(2) {
[‘name’] => Directory 1
[‘info’] => array(3) {
[0] => array(2) {
[‘name’] => File 1.a
[‘info’] => foo }
[1] => array(2) {
[‘name’] => File 1.b
[‘info’] => foo }
[2] => array(2) {
[‘name’] => File 1.c
[‘info’] => foo }
}
}
[1] => array(2) {
[‘name’] => File 2
[‘info’] => foo }
}
Each directory holds one array per file. Should that file be a directory itself it holds another array for those sub directories. This can be an arbitrary depth.
Now, I'm trying to take a GET variable (probably a string layed out as "3:0:1:...", but I'm up for alternative methods) that will tell the code how to navigate into the array and find the desired file. My thinking was that I would list which array index to go into so in the above string it would go to index 3, then in the array stored in that info index go to index 0 and then index 1, so-on-and-so-forth.
My question: Short of an eval() function - which I don't want to use until it's my last choice since the data is coming off a user input - is there a way to tell PHP how far to navigate into an array that may be an arbitrary size in any given dimension?
One last wrench in the works, I need the list to maintain state; it's in a session variable, so the process can't be destructive.
Thanks in advance for the help