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.
session_start();
$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;
}
}
var_dump($cart_items);