Afficher un array dans un <table>
Résolu
dberba
Messages postés
15
Statut
Membre
-
dberba Messages postés 15 Statut Membre -
dberba Messages postés 15 Statut Membre -
Bonjour,
je veux afficher ces deux tableaux:
<?php
$Nom = array("A","B");
$Date = array(1960,1975);
?>
dans un tableau ^^:
<table >
<tr>
<th>NOM</th>
<th>DATE</th>
</tr>
</table>
je veux afficher ces deux tableaux:
<?php
$Nom = array("A","B");
$Date = array(1960,1975);
?>
dans un tableau ^^:
<table >
<tr>
<th>NOM</th>
<th>DATE</th>
</tr>
</table>
1 réponse
-
-
-
Oui ça je sais que tu veux un résultat identique à ton image, mais en faisant un print_r comme je te l'ai déjà conseillé, à cet instant tu aurais DEJA le tableau correspondant au visuel de ton image. Maintenant, si tu n'as pas envie d'apprendre, ça ne regarde que toi, je ne vais pas apprendre à ta place...
-
-
Bon c'est déjà pas si mal, tu as enfin écouté un conseil!
Donc maintenant, tu as les clés du tableau $Nom et $Date, il ne te reste plus qu'à mettre en application et faire ton affichage ainsi :<?php $Nom = array("A","B"); $Date = array(1960,1975); ?> <table> <tr> <th>NOM</th> <th>DATE</th> </tr><tr> <td><?php echo $Nom[0]; ?></td> <td><?php echo $Date[0]; ?></td> </tr><tr> <td><?php echo $Nom[1]; ?></td> <td><?php echo $Date[1]; ?></td> </tr> </table>
Bien entendu, ceci fonctionnne pour des tableaux (array) dont on connait par avance les dimensions (nombre de clés=>valeurs). Pour un tableau dont on ne connait pas la dimension, il faudra certainement passé par une boucle et utilisé la fonction PHP sizeof()... -
Voilà j'ai réussi :p merci beaucoup
<style> table{border-collapse: collapse;} td, th{border: 1px solid black;} </style> <?php $Nom = array("A","B"); $Date = array(1960,1975); ?> <table> <tr> <th>NOM</th> <th>DATE</th> </tr> <?php $c=sizeof($Nom); for($i=0;$i<$c;$i++) { ?> <tr> <td><?php echo $Nom[$i]; ?></td> <td><?php echo $Date[$i]; ?></td> </tr> <?php } ?> </table>
-