Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Cupboard
- {
- protected $_items;
- public function addItem($item)
- {
- $this->_items[] = $item;
- return $this;
- }
- public function removeItem($item)
- {
- $key = array_search($item, $this->_items);
- unset ($this->_items[$key]);
- return $this;
- }
- public function listItems()
- {
- return implode(', ', $this->_items);
- }
- }
- $cb = new Cupboard();
- echo $cb->addItem('plate')
- ->addItem('cup')
- ->addItem('spoon')
- ->addItem('fork')
- ->removeItem('spoon')
- ->listItems() . PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement