appending arrays into session variable php
Im trying to add additional arrays into my session variable such as...
$_SESSION[cart] .= array($_POST[name],$_POST[price],$_POST[quantity]);
All i get when i do this 3 times and var_dump
is string(15) "ArrayArrayArray"开发者_C百科
Youre using .= "." is for string concat so youre arrays are getting converted to strings you should use one of the following:
$_SESSION['cart'][] = array($_POST[name],$_POST[price],$_POST[quantity]);
$_SESSION['cart'] += array($_POST[name],$_POST[price],$_POST[quantity]);
array_push(array($_POST[name],$_POST[price],$_POST[quantity]), (array) $_SESSION['cart'];
You can use print_r
and see the content of the array.
i.e., print_r($_SESSION)
精彩评论