【问题标题】:php - nested array: access parent array scope when have only inner referencephp - 嵌套数组:只有内部引用时访问父数组范围
【发布时间】:2018-09-16 16:38:58
【问题描述】:

让我们看看代码:

function update_by_ref(&$ref)
{
    $ref[] = 2;
    $ref[] = 3;        
}

$a = [];
$a_ref = &$a;

$b = [];
$b[] = &$a_ref;

update_by_ref($a_ref);
print_r ($b);

结果数组:

[[2,3]]

是否有任何选项可以从 update_by_ref() 函数中修改原始数组并获得如下内容:

[[2,3], [4,5]]

【问题讨论】:

    标签: php reference pass-by-reference


    【解决方案1】:

    不,这是不可能的。

    子元素没有关于父作用域的信息,可能没有父作用域。

    【讨论】:

      猜你喜欢
      • 2019-04-10
      • 2014-07-13
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2020-09-12
      相关资源
      最近更新 更多