php - How to store items recursively? -
i want collect& store data array while drilling structured data, when done, have array ex::
[{nodes:[{nodes:[], id:2}, {nodes:[{nodes:[], id:4}], id:3} ], id:1}]
notice how store deeper nodes parent nodes,here attempt simplified, tried pass node reference able collect deeper nodes 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]); // make sure drilling expected, used echo: echo ($newnode['id'].','); // now, push child node passed reference parent node: array_push($parentnode['nodes'], $childnode); // keep drilling, pass child node parent: $this->scan($childnode, $excel, $row, $column + 1, $maxcolumn); }
but, is:
{nodes:[{nodes:[],id:1}]}
why wouldn't expect? long pass childnode reference, should able build pyramid of nodes based on first passed node, right?
Comments
Post a Comment