title: PHP function array parameter by reference
body: <p>Why this code not works as I expected?
  Inside the Test(&amp;$array) function I would set the ref parameter to the global $array1 but this didn't works. </p>
  
  <pre><code>$array1 = array();
  $array2 = array();
  
  function Test(&amp;$array)
  {
      global    $array1;
      $array = &amp;$array1;
  
      $array['inside'] = 'inside';
  
  }
  </code></pre>
  
  <p>//SET BY THE FUNCTION:</p>
  
  <pre><code>Test($array2); 
  $array2['test1'] = 'test1';
  
  var_dump($array1); //array('inside' =&gt; 'inside') ** WHERE IS THE 'test1'  key? **
  var_dump($array2); //array('test1' =&gt; 'test1')   ** WHERE IS THE 'inside' key? **
  </code></pre>
  
  <p>//SET WITHOUT THE FUNCTION:</p>
  
  <pre><code>$array2 = &amp;$array1;
  $array2['test2'] = 'test2';
  
  var_dump($array1); //array('inside' =&gt; 'inside', 'test2' =&gt; 'test2') ** FINE **
  var_dump($array2); //array('inside' =&gt; 'inside', 'test2' =&gt; 'test2') ** FINE **
  </code></pre>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>It's quite clear that if I changed $array to point to $array1 then $array1 will have the 'inside' => 'inside' value <strong><em>outside</em></strong> the function. What not clear that if I set $array2['test1'] = 'test1' <strong>why not change this $array1 also</strong>? Its 'linked' before inside the function!</p>