Bonjour,
J'ai un problème sur l'affichage d'un tableau.
Je fais des saisies qui me remplissent un tableau de variable de session, jusque là tout va bien, je le remplis bien, preuve avec mon print_r($_SESSION) où j'ai bien mes saisies consécutives :
dans [libel] toto, tata, titi et dans [montant] 333, 777, 999
Mais le problème c'est quand je veux faire afficher chaque élément du tableau, il me sort les erreurs suivantes :
Notice: Undefined index: libel in ...
Notice: Undefined index: montant in ...
Je fais donc une erreur dans mon foreach, pouvez vous m'aider à afficher mon tableau comme suit :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 if(!isset($_SESSION['panier'])) { $_SESSION['panier'] = array(); } if ((isset($_POST['libel'])) and (isset($_POST['montant']))) { $_SESSION['panier']['libel'][] = $_POST['libel']; $_SESSION['panier']['montant'][] = $_POST['montant']; print_r($_SESSION); /* Array ( [panier] => Array ( [libel] => Array ( [0] => toto [1] => tata [2] => titi ) [montant] => Array ( [0] => 333 [1] => 777 [2] => 999 ) ) ) */ foreach ($_SESSION['panier'] as $cle => $elements) { echo $elements['libel'].", ".$elements['montant']."<br>"; } }
toto, 333
tata, 777
titi, 999
Merci d'avance.
Partager