Var_dump of an array shows just one variable

The var_dump of the $cart_items array is supposed to show an array of $cart_items with the quantities added together for the same id but it doesn’t even show an array, it just shows one value.

$cart_items = $_SESSION["cart_items"];
if ( $cart_items == null ) {
	$cart_items = array();
if ( isset($_REQUEST["element_id"]) ) {
	$id = $_REQUEST["element_id"];

if ( isset($_REQUEST["quantity"]) ) {
	$quantity = $_REQUEST["quantity"];

if ( isset($id)  && isset($quantity) ) {
if (isset($cart_items[$id])) {
	  	$cart_items[$id] += $quantity;

} else {
    $cart_items[$id] = $quantity;

Allowing user supplied values to be freely inserted into your code opens you up to a very nice hack attack. You need to validate the user supplied data. If your expecting a number, you should validate you are getting a valid number, etc, etc…

You also need to determine how you are getting the data. It is likely that it is only coming from either GET or POST, in which case you should not be using REQUEST.

I get

array (size=0)

from your code

Does the session data come from another page, or is it same page?

This has been solved on a different forum.

Sponsor our Newsletter | Privacy Policy | Terms of Service