title: Dynamically add arrays in PHP foreach loop
body: <p>I am trying to add new arrays to an existing array dynamically from a database but my loop is only adding the last row from mysql_fetch_row. I think it is actually overwriting the same array.</p>
  
  <p><strong>PHP Code</strong></p>
  
  <pre><code>&lt;?php
  $con = require_once('./dbconnect.php');
  
  global $con;
  mysql_select_db("packages", $con);
  $packages = mysql_query("SHOW TABLES FROM packages");
  
  while($row = mysql_fetch_row($packages)){
      $node = array();
  
      foreach($row as $key2 =&gt; $value2){
          $node[$row[0]] = array("Item1" =&gt; "Other dynamic Info here");
      }
  }
  
  print_r($node);
  
  mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>The output is as follows:</p>
  
  <pre><code>Array
  (
      [Pack1] =&gt; Array
          (
              [Item1] =&gt; Other dynamic Info here
          )
  
  )
  </code></pre>
  
  <p>It should be outputting:</p>
  
  <pre><code>Array
  (
      [Pack1] =&gt; Array
          (
              [Item1] =&gt; Other dynamic Info here
          )
  
  )
  Array
  (
      [Pack2] =&gt; Array
          (
              [Item2] =&gt; Other dynamic Info here
          )
  
  )
  </code></pre>
  
  <p><strong>I have been trying to get this foreach() loop to work for about a day now...what am i doing wrong?</strong></p>