title: Why does PHP NOT clear memory after leaving loops?
body: <pre><code>for($i=0; $i&lt;3; $i++) {
      echo '$i = ' . $i . '&lt;br/&gt;' ;
  }
  echo 'out of loop, $i = ' . $i;
  </code></pre>
  
  <p>the above outputs:</p>
  
  <pre><code>$i = 0
  $i = 1
  $i = 2
  out of loop, $i = 3
  </code></pre>
  
  <p>It doesn't make sense to me that $i is <em>still visible</em> even after displaying it out of the loop scope. Why does this happen (in java it's automatically garbage-collected)?</p>
  
  <p>And is there a way to tell php to <em>automatically</em> do garbage-collection after getting out of loop scope? My code looks ugly when I have to call <code>unset()</code> after each loop.</p>