j'essaie de voir clair dans le tuto sur les paniers :
J'ai un problème avec array_push(); qui n'accepte qu'un tableau en premier argument et donc ce code ne fonctionne pas.
http://www.php.net/manual/fr/function.array-push.php
l'erreur :
Code : Tout sélectionner
Warning: array_push() [function.array-push]: First argument should be an array in C:\apachefriends\xampp\htdocs\ajax\panier_cyrano\essai.php on line 23<?php
/* Démarrage ou prolongation de la session */
session_start();
/* Article exemple */
$select = array();
$select['id'] = "phlevis501";
$select['qte'] = 2;
$select['taille'] = "56";
$select['prix'] = 84.95;
/* On vérifie l'existence du panier, sinon, on le crée */
if(!isset($_SESSION['panier']))
{
/* Initialisation du panier */
$_SESSION['panier'] = array();
/* Subdivision du panier */
$_SESSION['panier']['qte'] = array();
$_SESSION['panier']['taille'] = array();
$_SESSION['panier']['prix'] = array();
}
/* Ici, on sait que le panier existe, donc on ajoute l'article dedans. */
array_push($_SESSION['panier']['id_article'],$select['id']);
array_push($_SESSION['panier']['qte'],$select['qte']);
array_push($_SESSION['panier']['taille'],$select['taille']);
array_push($_SESSION['panier']['prix'],$select['prix']);
/* Affichons maintenant le contenu du panier : */
?>
<pre>
<?php
var_dump($_SESSION['panier']);
?>
</pre>
et il précise qu'il vaut mieux utiliser pour insérer une donnée question de mémoire je suppose, mais je ne vois pas bien l'utilisation
<?php
$array[] = $var;
?>
Je pensait qu'en déclarant le tableau sa passerai, d'après le tuto ?
$_SESSION['panier'] = array();
D'ailleurs dans le test il manque
$_SESSION['panier']['id_article']
Merci