Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I have a multidimensional array in PHP that I would like to put in to a table in HTML. This is the array I have:

[2014-04-04] => Array
    (
        [0] => Array
            (
                [name] => Bob
                [uid] => 4tVydHSaLFwm9QbGfYtzwoyV5bfvEGn8
                [result] => 10.4
                [type] => a_breakfast
            )

        [1] => Array
            (
                [name] => Bob
                [uid] => 4tVydHSaLFwm9QbGfYtzwoyV5bfvEGn8
                [result] => 3.9
                [type] => b_lunch
            )

    )

[2014-04-05] => Array
    (
        [0] => Array
            (
                [name] => Bob
                [uid] => 4tVydHSaLFwm9QbGfYtzwoyV5bfvEGn8
                [result] => 3.5
                [type] => b_breakfast
            )

    )

How can I get it so that the table has the following:

|   DATE     |    BEFORE BREAKFAST  | AFTER BREAKFAST | BEFORE LUNCH | AFTER .... 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 2014-04-04 |                      |      10.4       |     3.9      |
| 2014-04-05 |       3.5            |                 |              |

I have tried multiple ways but I can not get it to work!

share|improve this question
3  
please show us what you have tried –  Aris Apr 5 '14 at 16:36
    
Have you even tried before you post your question? –  Marten Apr 5 '14 at 16:39

1 Answer 1

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>';

 ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.