title: Create HTML Table from nested PHP array
body: <p>I need some help, I am trying to create a dynamic HTML table that will display some results from a nested array.</p>
  
  <p>My array will always be setup like this:</p>
  
  <pre><code>Array
  (
      [column_label] =&gt; Size No.
      [column_data] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [column_cell] =&gt; #3
                  )
  
              [1] =&gt; Array
                  (
                      [column_cell] =&gt; #3.5
                  )
  
              [2] =&gt; Array
                  (
                      [column_cell] =&gt; #4
                  )
  
              [3] =&gt; Array
                  (
                      [column_cell] =&gt; #4.5
                  )
  
          )
  
  )
  
  Array
  (
      [column_label] =&gt; Approx. Diameter Inches
      [column_data] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [column_cell] =&gt; 3/32"
                  )
  
              [1] =&gt; Array
                  (
                      [column_cell] =&gt; 7/64"
                  )
  
              [2] =&gt; Array
                  (
                      [column_cell] =&gt; 1/8"
                  )
  
              [3] =&gt; Array
                  (
                      [column_cell] =&gt; 9/64"
                  )
  
          )
  
  )
  
  Array
  (
      [column_label] =&gt; Approx. Diameter mm
      [column_data] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [column_cell] =&gt; 2.38
                  )
  
              [1] =&gt; Array
                  (
                      [column_cell] =&gt; 2.78
                  )
  
              [2] =&gt; Array
                  (
                      [column_cell] =&gt; 3.18
                  )
  
              [3] =&gt; Array
                  (
                      [column_cell] =&gt; 3.57
                  )
  
          )
  
  )
  
  Array
  (
      [column_label] =&gt; Catalog No.
      [column_data] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [column_cell] =&gt; 32030
                  )
  
              [1] =&gt; Array
                  (
                      [column_cell] =&gt; 32035
                  )
  
              [2] =&gt; Array
                  (
                      [column_cell] =&gt; 32040
                  )
  
              [3] =&gt; Array
                  (
                      [column_cell] =&gt; 32045
                  )
  
          )
  
  )
  </code></pre>
  
  <p>I need to go through each <code>[column_data]</code> array and prepare them to display as table cells in my table.  </p>
  
  <p>For example a row in my table should include table cells from the column_data array with a key of 0.  The next row in my table will include table cells from the column_data array with a key of 1 and so on.</p>
  
  <p>Hope this makes sense, this way Im sure the cells will always correspond to Column_label table heading and be displayed vertically in cells.</p>
  
  <p>Here is my failed attempt (unfinished):</p>
  
  <pre><code>&lt;?php if ($product_table) { 
      //Setup empty arrays
      $products = array();
      $labels = array();
      $data = array();
      $column_cells = array();
  
      foreach($product_table as $product) { 
          //echo '&lt;pre&gt;';
          //print_r($product);
          //echo '&lt;/pre&gt;';
          //echo '&lt;th&gt;' . $product['column_label']  . '&lt;/th&gt;';
          $products[] = $product;
          $labels[] = $product['column_label'];
          $data[] = $product['column_data'];
  
              foreach ($product['column_data'] as $column_data) {
                  $column_cells[] = $column_data;
              }
          } 
  
  ?&gt;  
  
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;?php foreach($labels as $label) {
              echo '&lt;th&gt;' . $label . '&lt;/th&gt;';
          } ?&gt;
      &lt;/tr&gt;
  
      &lt;?php foreach($products as $product) { ?&gt;
      &lt;tr&gt;
          &lt;?php 
              echo '&lt;pre&gt;';
              print_r($product);
              echo '&lt;/pre&gt;';
          ?&gt;
      &lt;/tr&gt;
      &lt;?php } ?&gt;
  &lt;/table&gt;
  
  &lt;?php } ?&gt;
  </code></pre>