I am using this on a shopping cart
if (!empty($_getvars['id'])) {
$data = $session->get('cart');
$data[] = $_getvars['id'];
$session->set('cart', $data);
}
$_getvars['id'] is productid, and on each click, a new array element will be added to the session. It works fine as it is now, but if a product is chosen more than once a new array will be added, how can change it that productid will be array offset and the value will be incremented from 1 each time to reflect the quantity?
$i = 1;
if (!empty($_getvars['id'])) {
$data = $session->get('cart');
$data[$_getvars['id']] = $i++;
$session->set('cart', $data);
}
but this code each time resets to 1. How to fix it? Or any better array structure for a shopping cart?