par
Cyrano » 17 oct. 2005, 19:40
Il faudrait que tu utilises un tableau à deux dimensions, donc que "fichier" et "datefichier" soient des tableaux à l'intérieur du tableau $tab: dans ce cas, tu initialise au départ comme ceci:
<?php
$tab = array( "fichier" => array("toto.jpg"), "datefichier" => array("2005 05 05"));
?>
Première méthode pour ajouter des éléments
<?php
array_push($tab['fichier'],'tata.jpg');
array_push($tab['datefichier'], '2005 05 06');
?>
Méthode alternative pour faire exactement le même ajout
<?php
$tab['fichier'][] = 'tata.jpg';
$tab['datefichier'][] = '2005 05 06';
?>
Récupération et affichage
<?php
$nb = count($tab['fichier']);
echo("<ul>\n");
for($i = 0; $i < $nb; $i++)
{
echo("<li>Fichier ". $tab['fichier'][$i] ." du ". $tab['datefichier'][$i] .".</li>\n");
}
echo("</ul>\n");
?>
Il faudrait que tu utilises un tableau à deux dimensions, donc que "fichier" et "datefichier" soient des tableaux à l'intérieur du tableau $tab: dans ce cas, tu initialise au départ comme ceci:
[php]<?php
$tab = array( "fichier" => array("toto.jpg"), "datefichier" => array("2005 05 05"));
?>[/php]
Première méthode pour ajouter des éléments
[php]<?php
array_push($tab['fichier'],'tata.jpg');
array_push($tab['datefichier'], '2005 05 06');
?>[/php]
Méthode alternative pour faire exactement le même ajout
[php]<?php
$tab['fichier'][] = 'tata.jpg';
$tab['datefichier'][] = '2005 05 06';
?>[/php]
Récupération et affichage
[php]<?php
$nb = count($tab['fichier']);
echo("<ul>\n");
for($i = 0; $i < $nb; $i++)
{
echo("<li>Fichier ". $tab['fichier'][$i] ." du ". $tab['datefichier'][$i] .".</li>\n");
}
echo("</ul>\n");
?>[/php]