我有一个名为$currentTree
现在我想使用这个数组迭代和另一个名为$tree
所以,例如
$currentTree = array(5, 6, 2, 8);
变为
$tree[5][6][2][8] = "hello world"; //the values of $currentTree is used to get the appropriate child node of array $tree
我可以用任何预定义的PHP函数来实现这个目标吗?
答案 0 :(得分:4)
使用引用,这是 live demo
<?php
$currentTree = array(-1, 5, 6, 2, 8);
$ref = &$tree;
while($v = next($currentTree))
{
$ref = &$ref[$v];
}
$ref = "hello world";
print_r($tree);