I'm trying to use unset() with little success.
My cart array has this kind of format - a 2 dimensional array:
$cart[] = ($item = array(id => $id, qty => $qty, date_required => $date));
It's a bit more complex than a standard cart so I can't just store the product id and quantity to the array as a $key => $value pair. I also need to store variables such as the date the item is required and other user-selected options.
So my question is, what's the best method of deleting an $item[] from my $cart[]?
I've tried looping through each $cart[$row] unsing a foreach statement, using unset($cart[row]) when it needs to be deleted but it doesn't seem to be clearing the $item correctly.
I'm kinda new to this so I'm sure there's a much better way of doing it.
Any help will be appreciated.
Also, could one of the moderators please correct my awful typos in the topic title? Thanks,
How are you storing the cart contents from page to page? I tend to use a single delimited string which I decode/rebuild on every call of the cart script, so if I simply set the quantity field to zero and tell the rebuild code to ignore items with zero quantity, the item is deleted in that way.
Maybe you could work a similar idea into your code?