One way would be to use the unique ID of the product in question as an array key within $_SESSION
, e.g.$_SESSION['cart'][1234512]
. Then if a user added another item, I might do something like:
if(isset($_SESSION['cart'][$itemID]['quantity'])) {
$_SESSIONP['cart'][$itemID]['quantity'] = $_SESSION['cart'][$itemID]['quantity'] + $_POST['quantity'];
} else {
$_SESSIONP['cart'][$itemID]['quantity'] = $_POST['quantity'];
}