The missing (SPL) Collection/Array/OrderedMap interface.
A Collection resembles the nature of a regular PHP array. That is, it is essentially an <b>ordered map</b> that can also be used like a list.
A Collection has an internal iterator just like a PHP array. In addition, a Collection can be iterated with external iterators, which is preferrable. To use an external iterator simply use the foreach language construct to iterate over the collection (which calls {@link getIterator()} internally) or explicitly retrieve an iterator though {@link getIterator()} which can then be used to iterate over the collection. You can not rely on the internal iterator of the collection being at a certain position unless you explicitly positioned it before. Prefer iteration with external iterators.
@since 2.0 @author Guilherme Blanco <guilhermeblanco@hotmail.com> @author Jonathan Wage <jonwage@gmail.com> @author Roman Borschel <roman@code-factory.org>
Expanded class hierarchy of Collection
All classes that implement Collection
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Collection:: |
function | Adds an element at the end of the collection. | 1 | |
Collection:: |
function | Clears the collection, removing all elements. | 1 | |
Collection:: |
function | Checks whether an element is contained in the collection. This is an O(n) operation, where n is the size of the collection. | 1 | |
Collection:: |
function | Checks whether the collection contains an element with the specified key/index. | 1 | |
Collection:: |
function | Gets the element of the collection at the current iterator position. | 1 | |
Collection:: |
function | Tests for the existence of an element that satisfies the given predicate. | 1 | |
Collection:: |
function | Returns all the elements of this collection that satisfy the predicate p. The order of the elements is preserved. | 1 | |
Collection:: |
function | Sets the internal iterator to the first element in the collection and returns this element. | 1 | |
Collection:: |
function | Applies the given predicate p to all elements of this collection, returning true, if the predicate yields true for all elements. | 1 | |
Collection:: |
function | Gets the element at the specified key/index. | 1 | |
Collection:: |
function | Gets all keys/indices of the collection. | 1 | |
Collection:: |
function | Gets all values of the collection. | 1 | |
Collection:: |
function | Gets the index/key of a given element. The comparison of two elements is strict, that means not only the value but also the type must match. For objects this means reference equality. | 1 | |
Collection:: |
function | Checks whether the collection is empty (contains no elements). | 1 | |
Collection:: |
function | Gets the key/index of the element at the current iterator position. | 1 | |
Collection:: |
function | Sets the internal iterator to the last element in the collection and returns this element. | 1 | |
Collection:: |
function | Applies the given function to each element in the collection and returns a new collection with the elements returned by the function. | 1 | |
Collection:: |
function | Moves the internal iterator position to the next element. | 1 | |
Collection:: |
function | Partitions this collection in two collections according to a predicate. Keys are preserved in the resulting collections. | 1 | |
Collection:: |
function | Removes the element at the specified index from the collection. | 1 | |
Collection:: |
function | Removes the specified element from the collection, if it is found. | 1 | |
Collection:: |
function | Sets an element in the collection at the specified key/index. | 1 | |
Collection:: |
function | Extract a slice of $length elements starting at position $offset from the Collection. | 1 | |
Collection:: |
function | Gets a native PHP array representation of the collection. | 1 |