CollectionInterface
interface CollectionInterface implements ArrayInterface (View source)
A collection represents a group of objects, known as its elements.
Some collections allow duplicate elements and others do not. Some are ordered and others unordered.
Constants
SORT_ASC |
Ascending sort type. |
SORT_DESC |
Descending sort type. |
Methods
Ensures that this collection contains the specified element (optional operation).
Returns true
if this collection contains the specified element.
Returns the type associated with this collection.
Removes a single instance of the specified element from this collection, if it is present.
Returns the values from the given property or method.
Returns the first item of the collection.
Returns the last item of the collection.
Sort the collection by a property or method with the given sort order.
Filter out items of the collection which don't match the criteria of given callback.
Create a new collection where items match the criteria of given callback.
Apply a given callback method on each item of the collection.
Create a new collection with divergent items between current and given collection.
Create a new collection with intersecting item between current and given collection.
Merge current items and items of given collections into a new one.
Details
in ArrayInterface at line 29
void
clear()
Removes all items from this array.
in ArrayInterface at line 36
array
toArray()
Returns a native PHP array representation of this array object.
in ArrayInterface at line 43
bool
isEmpty()
Returns true
if this array is empty.
at line 59
bool
add(mixed $element)
Ensures that this collection contains the specified element (optional operation).
Returns true
if this collection changed as a result of the call.
(Returns false
if this collection does not permit duplicates and
already contains the specified element.)
Collections that support this operation may place limitations on what
elements may be added to this collection. In particular, some
collections will refuse to add null
elements, and others will impose
restrictions on the type of elements that may be added. Collection
classes should clearly specify in their documentation any restrictions
on what elements may be added.
If a collection refuses to add a particular element for any reason other
than that it already contains the element, it must throw an exception
(rather than returning false
). This preserves the invariant that a
collection always contains the specified element after this call returns.
at line 69
bool
contains(mixed $element, bool $strict = true)
Returns true
if this collection contains the specified element.
at line 76
string
getType()
Returns the type associated with this collection.
at line 86
bool
remove(mixed $element)
Removes a single instance of the specified element from this collection, if it is present.
at line 95
array
column(string $propertyOrMethod)
Returns the values from the given property or method.
at line 102
mixed
first()
Returns the first item of the collection.
at line 109
mixed
last()
Returns the last item of the collection.
at line 123
CollectionInterface
sort(string $propertyOrMethod, string $order = self::SORT_ASC)
Sort the collection by a property or method with the given sort order.
This will always leave the original collection untouched and will return a new one.
at line 139
CollectionInterface
filter(callable $callback)
Filter out items of the collection which don't match the criteria of given callback.
This will always leave the original collection untouched and will return a new one.
See the {@link http://php.net/manual/en/function.array-filter.php PHP array_filter() documentation}
for examples of how the $callback
parameter works.
at line 152
CollectionInterface
where(string $propertyOrMethod, mixed $value)
Create a new collection where items match the criteria of given callback.
This will always leave the original collection untouched and will return a new one.
at line 168
CollectionInterface
map(callable $callback)
Apply a given callback method on each item of the collection.
This will always leave the original collection untouched and will return a new one.
See the {@link http://php.net/manual/en/function.array-map.php PHP array_map() documentation}
for examples of how the $callback
parameter works.
at line 179
CollectionInterface
diff(CollectionInterface $other)
Create a new collection with divergent items between current and given collection.
at line 190
CollectionInterface
intersect(CollectionInterface $other)
Create a new collection with intersecting item between current and given collection.
at line 199
CollectionInterface
merge(CollectionInterface ...$collections)
Merge current items and items of given collections into a new one.