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>
A voir également:
- Afficher un array dans un <table>
- Table ascii - Guide
- Table des matières word - Guide
- Afficher le 0 devant un nombre dans excel - Guide
- Afficher calendrier outlook dans google agenda - Guide
- Table des caractères - Guide
http://img15.hostingpics.net/pics/782747cske.png
merci pour ta réponse ^-^
Avec print_r ça donne :
Array
(
[0] => A
[1] => B
)
Array
(
[0] => 1960
[1] => 1975
)
comment puis-je avoir le résultat dans un tableau?
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()...
<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>