dty9731 2012-06-18 14:08
浏览 62
已采纳

PHP变量来访问数组中的变量

Not being used to php, I'm facing an issue with accessing arrays and its sub data.

$form['signatories']['signatory1'] = array(...);

I must create a "pointer" to the array created in the line above, I expected the following to work:

$cluster = $form['signatories']['signatory1'];

Testing I'm accessing the same "memory space" proves I'm wrong:

$cluster['signatory_name'] = array(...)
// $form['signatories']['signatory1'] has no elements
// $cluster has a sub element

Like cluster is a copy of the array I want it to point to.

How should I proceed? I tried using the "&" reference sign as mentioned in some blog, but that didn't help.

Thanks! J.

  • 写回答

2条回答 默认 最新

  • douchibu7040 2012-06-18 14:11
    关注

    By default, assignment in PHP is by value, not by reference, except for objects.

    If you want to pass a reference to the original array, you need to create a reference explicitly:

    $cluster = &$form['signatories']['signatory1'];
    

    See assigning by reference in the PHP manual.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀