Okay, I got this to work using eval( ). (Question to follow)
What I did is put this into a class, and keep track of the array by setting the values rather than trying to merge the arrays together on each recursive call.
Then what I do is keep track of the current location, so I form a string that looks like this:
$str = '$this->tree' . $location . '[\'' . $key . '\']' . ' = $children{$key};';
Where $location is a string that looks like this:
['solutions']['site-development'] etc
Then I eval $str, and it basically sets the array value of $this->tree. At the end of the function, I can access $this->tree - my entire navigation tree.
My question is this: what are the security implications of doing this? I realize I am using eval(), however, I am only eval()'ing the page ID's. Granted, the user of my CMS has access to specify the page id, and this could be a vulnerability as they could stick some PHP code in there.
However, what if I added form validation that prohibited them from inputting certain characters as the page id. I'll need some help coming up with these, but they may include
<?
;
'
\
/
(
)
Basically, only allow text and - or _, not even spaces will be allowed.
By doing this, can I rest assured that I'm not going to be exploited, or is there something I'm missing?
Also, is this a fairly efficient way of managing my navigation? It seems better than nested queries, and the recursive call should be pretty fast. I doubt many sites will have more than 100 pages, and even that is a stretch!