PHP动态获取子数组

PHP动态获取子数组,php,arrays,dynamic,Php,Arrays,Dynamic,我有一个名为$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函数可以用来实现这一点吗?使用参考,这里是 <?php $c

我有一个名为
$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函数可以用来实现这一点吗?

使用参考,这里是

<?php
$currentTree = array(-1, 5, 6, 2, 8);
$ref = &$tree;
    while($v = next($currentTree))
    {
      $ref = &$ref[$v];
    }
    $ref = "hello world";

    print_r($tree);

使用参考,这里是

<?php
$currentTree = array(-1, 5, 6, 2, 8);
$ref = &$tree;
    while($v = next($currentTree))
    {
      $ref = &$ref[$v];
    }
    $ref = "hello world";

    print_r($tree);

你试过什么吗?为什么要这么做?我相信会有比这更好的方法;我尝试使用数组推送,但这会完全删除节点并在其位置生成一个新数组。获取数组索引的格式是相同的还是不同的。?例如:对于5,6,2,8,数组索引将是2,3,4,5。不,对于5,6,2,8,数组索引也将是5,6,2,8。基本上我会从另一个数组中获取数组索引你试过什么了吗?你为什么要这么做?我相信会有比这更好的方法;我尝试使用数组推送,但这会完全删除节点并在其位置生成一个新数组。获取数组索引的格式是相同的还是不同的。?例如:对于5,6,2,8,数组索引将是2,3,4,5。不,对于5,6,2,8,数组索引也将是5,6,2,8。基本上,我将从另一个数组中获取数组索引。那么,您能解释一下
&
的作用吗?它是指针参考吗?这是&参考手册,您能解释一下
&
的功能吗?它是指针参考吗?这是参考手册(&R)