title: unset variable in foreach recursively
body: <p>I need build tree hierarchy through recursion. 
  All working fine without php unset, but I want unset elements which already been built.</p>
  
  <p><strong>Problem:</strong> In code below unset working, but break the first recursion call, so from the example data  category where id=5 not rendering.  </p>
  
  <p>Any ideas, very interesting what's wrong</p>
  
  <pre><code> function renderMenu(&amp;$tempTree, $parentId){
          foreach($tempTree as $row) {
              if ($row['parent_id'] == $parentId) {
                  $id = $row["category_id"];
                  echo $row['name'].'&lt;br&gt;';
                  unset($tempTree[$id]);
                 if (isset($row['has_child'])){
                     renderMenu($tempTree, $id);
                  }
  
              }
          }
      }
  
  $s=array ( '1' =&gt; Array ( 'category_id' =&gt; 1,
  'parent_id' =&gt; 0,
  'name' =&gt; '1' ),
  
  '2' =&gt; Array ( 'category_id' =&gt; 2,
  'parent_id' =&gt; 0,
  'has_child' =&gt; true,
  'name' =&gt; '2'),
  
  '3' =&gt; Array ( 'category_id' =&gt; 3,
  'parent_id' =&gt; 2,
  'name' =&gt; '3'),
  
  '4' =&gt; Array ( 'category_id' =&gt; 4,
  'parent_id' =&gt; 2,
  'name' =&gt; '4'),
  
  '5' =&gt; Array ( 'category_id' =&gt; 5,
  'parent_id' =&gt; 0,
  'name' =&gt; '5' )
  );
  
  
  
  renderMenu($s,0);
  </code></pre>