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.

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.

You can use =& to assign by reference:

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

Effectively this is two operations. The first is &$form['signatories']['signatory1'] which gives you a reference to $form['signatories']['signatory1']. The second is = which obviously assigns the reference to $cluster.