All pastes #961552 Raw Edit

Miscellany

public php v1 · immutable
#961552 ·published 2008-03-28 23:35 UTC
rendered paste body
<?phpclass Cart {    var $items;  // Items in our shopping cart    // Add $num articles of $artnr to the cart    function add_item($artnr, $num) {        $this->items[$artnr] += $num;    }    // Take $num articles of $artnr out of the cart    function remove_item($artnr, $num) {        if ($this->items[$artnr] > $num) {            $this->items[$artnr] -= $num;            return true;        } elseif ($this->items[$artnr] == $num) {            unset($this->items[$artnr]);            return true;        } else {            return false;        }}?>