title: PHP, assigning a value to a variable by reference
body: <p>a friend asked me to analyze the output of the following simple lines.
  I defined a variable <strong>x</strong> that has the string <em>PHP</em>, and a table called <em><strong>a</strong></em> which is a reference to <em><strong>x</strong></em>, so any changes to one of them will affect the other. First, I assigned the value <em>&quot;Mysql&quot;</em> to the first element of <em><strong>a</strong></em>, the value of <em><strong>x</strong></em> changed too.
  But in the second affectation, when the second element of the table <em><strong>a</strong></em> got the value <em>&quot;test&quot;</em>, the value of the variable <em><strong>x</strong></em> didn't change, any explanation?</p>
  <pre><code>&lt;?php
      $x = &quot;PHP&quot;;
  
      $a[] = &amp;$x;
      $a[0] = &quot;MySql&quot;;
      
      echo $a[0]; // Output: MySql
      echo $x;   // Output: MySql
  
      $a[1] = &quot;test&quot;;
      echo $a[1]; // Output: test
      echo $x; // Output: MySql
      // why last output is mySql and not test?
  ?&gt;
  </code></pre>