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 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <?php
$tablo = array();
$tablo['ecole 1'] = array('nom A', 'nom B');
$tablo['ecole 2'] = array('nom C', 'nom D', 'nom E');
$output = '<table>';
$max = 0;
//On recupère le nom des écoles :
$ecoles = array_keys($tablo);
//On construit l'entete du tableau
$output .= '<thead><tr>';
foreach($ecoles as $ecole) {
$output .= '<th>'.$ecole.'</th>';
//On en profite pour compter le max
if ($max < count($tablo[$ecole])) {
$max = count($tablo[$ecole]);
}
}
$output .= '</tr></thead>';
//On construit le corp du tableau
$output .= '<tbody>';
for($i = 0 ; $i < $max ; $i++) {
$output .= '<tr>';
foreach($ecoles as $ecole) {
$output .= '<td>';
if (isset($tablo[$ecole][$i])) {
$output .= $tablo[$ecole][$i]; //Le nom appartenant à l'ecole
} else {
$output .= ' '; // Il n'y a plus de nom pour cette ecole
}
$output .= '</td>';
}
$output .= '</tr>';
}
$output .= '</tbody>';
$output .= '</table>';
//On affiche
echo $output;
?> |
Partager