I am building a simple cart for a friend and using an array in session to store it.
To add an item to the cart I have this code
$next_item = sizeof($_SESSION['cart']) +1;
$_SESSION['cart'][$next_item] = array(item => $product_id, option => $option, qty => 1);
What I’m struggling with how to update an item’s quantity in this array should someone add another of the same item or update the cart. Can anyone point me in the right direction? Thanks
Something like
I would change the structure of your array.
Instead of
Use
Where the key is the product id. It will make referencing the items easier and you can update the quantity in one line