I want to collect& store data into an array while drilling into some structured data, so that when I am done, I have an array like this for ex::
[{nodes:[{nodes:[], id:2}, {nodes:[{nodes:[], id:4}], id:3} ], id:1}]
Notice how I store deeper nodes into parent nodes,Here is my attempt simplified, as I tried to pass node by reference to be able to collect deeper nodes into their parent nodes:
$parentNode= array('nodes'=>array());
scan ($parentNode, $excel, 0, 0);
function scan (& $parentNode, $excel, $row, $column, $maxColumn)
{
$childNode = array('nodes' => array(), 'id' => $excel[$row]['cr'.$column]);
// to make sure I am drilling as expected, I used echo:
echo ($newNode['id'].',');
// now, push the child node into the passed by reference parent node:
array_push($parentNode['nodes'], $childNode);
// keep drilling, pass child node as parent:
$this->scan($childNode, $excel, $row, $column + 1, $maxColumn);
}
But, what I get is:
{nodes:[{nodes:[],id:1}]}
Why wouldn't I get what I expect? As long as I pass childNode by reference, I should be able to build my pyramid of nodes based on first passed node, right?