1

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"

2 Answers 2

3

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'];
Sign up to request clarification or add additional context in comments.

Comments

0

You can use print_r and see the content of the array.

i.e., print_r($_SESSION)

1 Comment

Var_dump often gives more information then print_r. I really don't see how or why this would be any help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.