Public feed #961552

Miscellany

public php v1 · immutable
Raw Edit
·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;        }}?>