Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Cupboard
- {
- protected $_items;
- public function __construct()
- {
- $this->_items = array();
- }
- public function insert($item)
- {
- $this->_items[] = $item;
- return $this;
- }
- public function remove($item)
- {
- if (($key = array_search($item, $this->_items)) !== FALSE) {
- unset($this->_items[$key]);
- }
- return $this;
- }
- public function getAll()
- {
- return $this->_items;
- }
- }
- $cup = new Cupboard;
- var_dump($cup->insert('spoon')->insert('knife')->remove('spoon')->insert('plate')->getAll());
- // ['knife', 'plate']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement