PHP Multidimensional associative array to HTML table

Use this Code hope this will help you .
if not then you can get at least a basic idea from it .

<?php

  $values = array(
   'Index' => array(
        'Date' => '10-10-13',
       'Name' => 'Azi Baloch',
       'Number' => '12345'
    ),
   'Index2' => array(
        'Date' => '11-10-13',
        'Name' => 'Asad Butt',
        'Number' => '123321'
    )
    );

 $array = array_values($values);


  // Genrate HTML
  echo '<table border=1 width=800>';
  echo '<tr><td>Category</td><td>Name</td><td>Number</td></tr>';
  for($i = 0; $i< count($array); $i++) {
    echo '<tr>';
    echo '<td>'.$array[$i]['Date'].'</td>';
    for($j = 1; $j<count($array[$i]); $j++) {
        $n = array_values($array[$i]);

        echo '<td>'. $n[$j] .'</td>';
    }
    echo '</tr>';
  }
  echo '</table>';

 ?>

Leave a Comment