objs, $obj); else $this->objs[$key] = $obj; return $key == null ? $this->len - 1 : $key; } /** * Remove an element in collection. * * The function will first look for the element as a * index key, but if its not found it will look for the * element as a value. * * Deep functions only when the value is given and not the key. * * @param mixed $any Index key or element value * @param bool $deep Delete every item and not just the first * @return bool */ public function remove($any, bool $deep = true) { if (isset($this->objs[$any])) { unset($this->objs[$any]); return true; } else if (in_array($any, $this->objs)) { $key = array_search($any, $this->objs, true); // No need to add deep ($key deletion) $val = $this->remove($key); if ($val && $deep) // Delete every object $this->remove($any, $deep); return $val; } return false; } /** * @see \Gogs\Lib\ArrayIterator */ public function all() { return $this->objs; } /** * @see \Gogs\Lib\ArrayIterator */ public function len() { return count($this->objs); } /** * @see \Gogs\Lib\ArrayIterator */ public function by_key($idx) { return isset($this->objs[$idx]) ? $this->objs[$idx] : false; } /** * @see \Gogs\Lib\ArrayIterator */ public function next() { return next($this->objs); } /** * @see \Gogs\Lib\ArrayIterator */ public function prev() { return prev($this->objs); } /** * @see \Gogs\Lib\ArrayIterator */ public function current() { return current($this->objs); } /** * @see \Gogs\Lib\ArrayIterator */ public function reset() { return reset($this->objs); } /** * Search for an object. * * @param array $params Parameters * @return \Gogs\Lib\Collection */ abstract public function search(array $params = array()); } } ?>