In php there is variable variable names:
As the example goes:
$a = 'hello';
$$a = 'world';
echo $hello; // outputs world
Now, we also have nested arrays:
$myvar = Array(
'a' => Array('b' => 1, 'c' => 2),
'd' => Array('e' => 3, 'f' => 4)
);
echo $myvar['a']['e']; // outputs e
Question: is it possible to access such array with variable names?
Something like the following:
$myvarname = 'myvar[a][e]';
echo $$myvarname;
If yes - how?
EDIT:
What I am trying to do is build an array in a loop. I have no idea about the incoming data, so array can be any level of depth.
There is a number of input rows formatted like this:
/katalog/category1/subcategory1/subcategory2
I made a loop through input lines, and split the URLs with "/".
After that I am trying to build an array, which will represent the structure of all urls.
category 1
--> subcategory 1
--> subcategory 2
--> subcategory 3
--> subcategory 4
category 2
--> subcategory 5
category 3
category 4
The main part of the question is how to use variable variable for nested array. If at all possible. I included the actual use case because it was asked from me how that can be used in real life. Don't need a solution to my problem - I can solve that question myself.
However, variable variable usage - that is the real question.