我想收集&在钻取到一些结构化数据的同时将数据存储到数组中,这样当我完成时,我有一个这样的数组,用于ex ::
[{nodes:[{nodes:[], id:2}, {nodes:[{nodes:[], id:4}], id:3} ], id:1}]
注意我如何将更深的节点存储到父节点中,这是我的尝试简化,因为我试图通过引用传递节点,以便能够将更深的节点收集到其父节点中:
$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);
}
但是,我得到的是:
{nodes:[{nodes:[],id:1}]}
为什么我不能得到我所期望的?只要我通过引用传递childNode,我应该能够根据第一个传递的节点构建我的节点金字塔,对吗?