开发者

appending arrays into session variable php

开发者 https://www.devze.com 2022-12-12 09:50 出处:网络
Im trying to add additional arrays into my session variable such as... $_SESSION[cart] .= array($_POST[name],$_POST[price],$_POST[quantity]);

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消