title: Foreach loop into table from array data php
body: <p>I have an array like so: var_export():</p>
  
  <blockquote>
    <p>array ( 2009 => array ( 'Jan' => array ( 'AMT' => '79', 'QTY' =>
    '886', ), 'Apr' => array ( 'AMT' => '0', 'QTY' => '1', ), 'May' =>
    array ( 'AMT' => '19', 'QTY' => '216', ), 'Jun' => array ( 'AMT' =>
    '5', 'QTY' => '60', ), 'Sep' => array ( 'AMT' => '20', 'QTY' => '196',
    ), 'Oct' => array ( 'AMT' => '0', 'QTY' => '1', ), 'Feb' => array (
    'AMT' => 0, 'QTY' => 0, ), 'Mar' => array ( 'AMT' => 0, 'QTY' => 0, ),
    'Jul' => array ( 'AMT' => 0, 'QTY' => 0, ), 'Aug' => array ( 'AMT' =>
    0, 'QTY' => 0, ), 'Nov' => array ( 'AMT' => 0, 'QTY' => 0, ), 'Dec' =>
    array ( 'AMT' => 0, 'QTY' => 0, ), ), 2010 => array ( 'Mar' => array (
    'AMT' => '12', 'QTY' => '131', ), 'Apr' => array ( 'AMT' => '0', 'QTY'
    => '1', ), 'Jun' => array ( 'AMT' => '6', 'QTY' => '65', ), 'Jul' => array ( 'AMT' => '24', 'QTY' => '205', ), 'Aug' => array ( 'AMT' =>
    '20', 'QTY' => '169', ), 'Sep' => array ( 'AMT' => '0', 'QTY' => '1',
    ), 'Oct' => array ( 'AMT' => '106', 'QTY' => '1118', ), 'Nov' => array
    ( 'AMT' => '85', 'QTY' => '902', ), 'Dec' => array ( 'AMT' => '0',
    'QTY' => '2', ), 'Jan' => array ( 'AMT' => 0, 'QTY' => 0, ), 'Feb' =>
    array ( 'AMT' => 0, 'QTY' => 0, ), 'May' => array ( 'AMT' => 0, 'QTY'
    => 0, ), ), 2011 => array ( 'Mar' => array ( 'AMT' => '0', 'QTY' => '3', ), 'Sep' => array ( 'AMT' => '74', 'QTY' => '582', ), 'Oct' =>
    array ( 'AMT' => '6', 'QTY' => '60', ), 'Nov' => array ( 'AMT' =>
    '46', 'QTY' => '462', ), 'Jan' => array ( 'AMT' => 0, 'QTY' => 0, ),
    'Feb' => array ( 'AMT' => 0, 'QTY' => 0, ), 'Apr' => array ( 'AMT' =>
    0, 'QTY' => 0, ), 'May' => array ( 'AMT' => 0, 'QTY' => 0, ), 'Jun' =>
    array ( 'AMT' => 0, 'QTY' => 0, ), 'Jul' => array ( 'AMT' => 0, 'QTY'
    => 0, ), 'Aug' => array ( 'AMT' => 0, 'QTY' => 0, ), 'Dec' => array ( 'AMT' => 0, 'QTY' => 0, ), ), )</p>
  </blockquote>
  
  <p>I have been using an array with only a single nested array and displaying my data in a table like this:</p>
  
  <pre><code>foreach($results as $key =&gt; $element){
      echo "&lt;tr&gt;";
      foreach($element as $subkey =&gt; $subelement){
          echo "&lt;td width='20%'&gt;$subelement&lt;/td&gt;";
      }
      echo "&lt;/tr&gt;";
  }
  </code></pre>
  
  <p>However, now I have Year (2009,2010,2011) and am not sure how to get it into my table. Before I was just showing Month, Amt, Qty... hence the foreach above.</p>
  
  <p>I'd like to display it like so:</p>
  
  <p>Year | Month | Amt | Qty</p>
  
  <p>I was trying to capture the year in an if statement, if(2009){show $subelement} type of idea...</p>