19declare(strict_types=1);
40 return new ArrayIterator($this->elements);
56 return $this->
get($offset);
64 if (!isset($offset)) {
70 $this->
set($offset, $value);
78 $this->
remove($offset);
86 return count($this->elements);
92 public function add($element): void
94 $this->elements[] = $element;
100 public function remove(
$key):
void
103 throw new InvalidArgumentException(sprintf(
'Could not find an element for key: %s',
$key));
105 unset($this->elements[
$key]);
113 $key = array_search($element, $this->elements,
true);
114 if (
false ===
$key) {
115 throw new InvalidArgumentException(
'Could not find an key for the passed element.');
117 unset($this->elements[
$key]);
128 return isset($this->elements[
$key]) || array_key_exists(
$key, $this->elements);
136 return array_search($element, $this->elements,
true);
144 $this->elements = [];
152 return in_array($element, $this->elements,
true);
160 return $this->elements[
$key] ??
null;
166 public function set(
$key, $value):
void
168 $this->elements[
$key] = $value;
176 return empty($this->elements);
184 return array_keys($this->elements);
192 return array_values($this->elements);
200 return new static(array_filter($this->elements, $callable));
208 return new static(array_slice($this->elements, $offset, $length,
true));
221 if (!($other instanceof
self)) {
226 $other = $other->toArray();
231 return $self == $other;
Class ilBuddySystemArrayCollection A collection which contains all entries of a buddy list.
getKey($element)
@inheritDoc
offsetSet($offset, $value)
@inheritDoc
contains($element)
@inheritDoc
slice(int $offset, int $length=null)
@inheritDoc
offsetGet($offset)
@inheritDoc
containsKey($key)
isset is used for performance reasons (array_key_exists is much slower).
__construct(array $elements=[])
offsetUnset($offset)
@inheritDoc
filter(callable $callable)
@inheritDoc
removeElement($element)
@inheritDoc
offsetExists($offset)
@inheritDoc
Interface ilBuddySystemCollection.