I have a tree structure in the format:
Array
(
[0] => TEST
[1] => Array
(
[0] => TEST
[1] => number
[2] => 4321
)
[2] => Array
(
[0] => TEST
[1] => Array
(
[0] => TEST
[1] => Array
(
[0] => TEST
[1] => part
[2] =>
)
[2] => Array
(
[0] => TEST
[1] => number
[2] => 1234
)
)
)
)
I am trying ot traverse the thing and add a root node to each non-leaf node so no matter where I am in the tree I can reverse backwards if needed.
I have this code but for the life of me I cannot figure out why the arrays are not referenceing. I am certain I have done this in the past as I remember referenced nodes dump as recursion or something similar but again obviously my code is not properly referencing nodes as entire copies are insrted instead of the recursion I was hoping for.
function tree_make_bidirectional(&$elements)
{
$temp = array();
$temp['ROOT'] = &$elements;
foreach($elements as &$element){
if(is_array($element)){
$temp[] = tree_make_bidirectional($element);
}
else{
$temp[] = &$element;
}
}
return $temp;
}
Anyone spot the issue and care to point it out?
Cheers,
Alex