Hello,
I've got a simple cart class that holds the cart in an associative array with pairs $item_id => $quantity. I've built a cleanup method that, in theory, should rebuild the cart array leaving out items w/ quantity 0, but somewhere it fails. Could someone have a look?
Thanks,
Steve
// remove items of zero quantity from cart
function clean()
{
$fresh_array = array(); // new array to be built
$old_array = $this->items; // old cart array
foreach ($old_array as $k => $v) { // for each pair in old array..
if ($v > 0) { // if quantity is > 0 then add it to new array
$add_me = array($k => $v);
$fresh_array = array_merge($fresh_array,$add_me);
}
}
$this->items = $fresh_array;
}