fix #31008: first example had a little bug

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@174277 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Nuno Lopes 2004-12-08 11:59:35 +00:00
parent aa43cb1caa
commit e2c756356f

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.55 $ -->
<!-- $Revision: 1.56 $ -->
<chapter id="language.oop">
<title>Classes and Objects (PHP 4)</title>
@ -16,22 +16,25 @@
<?php
class 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;
}
}
}
}
?>