How to create tables from array in php

Use foreach, it should be quite simply:

<?php

$array = array(
    'data' => array (
        1048 => array(
            'email' => 'XXX',
            'name' => '...',
            'comment' => '...'
        ),
        1115 => array(
            'email' => 'XXX',
            'name' => '...',
            'comment' => '...'
        )
    )
);

echo '<table>';
echo '<tr>';
    echo '<th>ID';
    echo '<th>Email';
    echo '<th>Name';
    echo '<th>Comment';

    foreach ($array['data'] as $id => $row) {
        echo '<tr>';
            echo '<td>' . $id;
            echo '<td>' . $row['email'];
            echo '<td>' . $row['name'];
            echo '<td>' . $row['comment'];
    }
echo '</table>';

?>

Leave a Comment