title: Understanding PHP dangling array references
body: <p>Here is the code I've found on the web:</p>
  
  <pre><code>$array = [1, 2, 3];
  echo implode(',', $array), "\n";
  
  foreach ($array as &amp;$value) {}    // by reference
  echo implode(',', $array), "\n";
  
  foreach ($array as $value) {}     // by value (i.e., copy)
  echo implode(',', $array), "\n";
  </code></pre>
  
  <p>I want to understand why this happens.
  Can someone explain what happens with the reference each step. I know about this "bug" but I want to understand why is this happening.</p>
  
  <p>BTW The output is:</p>
  
  <pre><code>1,2,3
  1,2,3
  1,2,2
  </code></pre>