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
| <?php
// -----------------
$data = array(
array("Nom"=>"Garza","Prenom"=>"Forrest","Email"=>"eleifend@ligulaedu","Taille"=>"185","Poids"=>"65"),
array("Nom"=>"Tanner","Prenom"=>"Orla","Email"=>"adipiscing@vitaecouk","Taille"=>"180","Poids"=>"73"),
array("Nom"=>"Griffith","Prenom"=>"Susan","Email"=>"condimentum@tristiqueca","Taille"=>"172","Poids"=>"75"),
array("Nom"=>"Wilkinson","Prenom"=>"Carla","Email"=>"tinciduntaliquamarcu@utmolestieca","Taille"=>"178","Poids"=>"71"),
array("Nom"=>"Kirkland","Prenom"=>"Vladimir","Email"=>"Donec@egettinciduntduiorg","Taille"=>"178","Poids"=>"73"),
array("Nom"=>"Holloway","Prenom"=>"Joy","Email"=>"enim@Nullamca","Taille"=>"191","Poids"=>"67"),
array("Nom"=>"Soto","Prenom"=>"Cleo","Email"=>"posuereatvelit@Incondimentumca","Taille"=>"167","Poids"=>"70"),
);
// -----------------
// lignes du tableau
$t_body = '';
foreach( $data as $perso )
{
$t_body .= '<tr>'."\n"; // "\n" : passage à la ligne dans le code (pour plus de clarté)
foreach( $perso as $val )
{
$t_body .= '<td>'.$val.'</td>'."\n";
}
$t_body .= '</tr>'."\n";
}
// -----------------
// entete du tableau
$data_entete = array_keys($data[0]); // on prend les clés de la 1ere ligne
$t_head = '<tr>'."\n";
foreach( $data_entete as $titre )
{
$t_head .= '<th>'.$titre.'</th>'."\n";
}
$t_head .= '</tr>'."\n";
// -----------------
// Affichage
?>
<table>
<thead>
<?php echo $t_head; ?>
</thead>
<tbody>
<?php echo $t_body; ?>
</body>
</table> |
Partager