toastrom Posted April 6, 2009 Report Share Posted April 6, 2009 (edited) Hi, I'm new with this OOP and I try to remove an item quantity from the array. I don't know if this way is ok but works with: public function RemoveItem($product_id) { $this->items[$product_id] = $this->items[$product_id] - 1; } My problem is, how to delete the whole item from the array when the item quantity is 0? if $this->items[$product_id] == 0; unset($this->items[$product_id]); Something like that, or? I can't get it work in the Killer shopping cart! Thanks toastrom Edited April 7, 2009 by toastrom Quote Link to comment Share on other sites More sharing options...
toastrom Posted April 7, 2009 Author Report Share Posted April 7, 2009 Can "You" please confirm that this code is OK? It do the job but as I said, I'm trying to learn. public function RemoveItem($product_id) { if (array_key_exists($product_id , $this->items)) $this->items[$product_id] = $this->items[$product_id] - 1; if ($this->items[$product_id] == 0) { unset($this->items[$product_id]); } } TIA toastrom Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.