1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?php
$T = array(
'col_1' => ['A', 'B', 'C'],
'col_2' => ['D', 'E'],
'col_3' => ['F', 'G', 'H', 'I']
);
$count_rows = array_map('count', $T);
rsort($count_rows);
$count_rows = $count_rows[0];
$cols = array_keys($T);
echo '<table>';
// colonnes
echo '<tr>';
echo '<td></td>';
foreach ($cols as $col_name) echo '<td>', $col_name, '</td>';
echo '</tr>', "\n";
// lignes
for ( $i=0; $i<$count_rows; $i ++) {
echo '<tr>';
echo '<td>Ligne ', ($i+1), '</td>';
foreach ($T as $rows) {
echo '<td>', (isset($rows[$i]) ? $rows[$i] : ''), '</td>';
}
echo '</tr>', "\n";
}
echo '</table>'; |
Partager