24 public function add($element)
26 $this->elements[] = $element;
31 return isset($this->elements[
$key]) ? $this->elements[
$key] : null;
36 return new self(array_filter($this->elements, $f));
39 public function set(
$key, $value)
41 $this->elements[
$key] = $value;
44 public function remove($element)
46 $key = array_search($element, $this->elements);
52 $removed = $this->elements[
$key];
53 unset($this->elements[
$key]);
60 if ($this->
count() !== 1) {
62 __CLASS__ .
'::' . __METHOD__ .
' requires that the collection has exactly one element, ' 63 .
'"%d" elements found',
68 return reset($this->elements);
73 return reset($this->elements);
78 return end($this->elements);
83 return new self(array_map($function, $this->elements));
88 return count($this->elements);
93 return new \ArrayIterator($this->elements);
98 return isset($this->elements[$offset]);
103 return $this->elements[$offset];
108 $this->elements[$offset] = $value;
113 unset($this->elements[$offset]);
offsetSet($offset, $value)
add($element)
Add an element to the collection.
first()
Return the first element from the collection.
getOnlyElement()
Shorthand for getting a single element that also must be the only element in the collection.
__construct(array $elements=array())
last()
Return the last element from the collection.
Simple Array implementation of Collection.
Create styles array
The data for the language used.
map(\Closure $function)
Applies the given function to each element in the collection and returns a new collection with the el...