Doctrine\Common\Collections\Collection
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 internally) or
explicitly retrieve an iterator though 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.
- Author: Guilherme Blanco <guilhermeblanco@hotmail.com>
Synopsis
interface Collection
extends Countable, IteratorAggregate, ArrayAccess
{
- // methods
- public boolean add()
- public void clear()
- public boolean contains()
- public boolean isEmpty()
- public mixed remove()
- public boolean removeElement()
- public boolean containsKey()
- public mixed get()
- public array getKeys()
- public array getValues()
- public void set()
- public array toArray()
- public mixed first()
- public mixed last()
- public void key()
- public void current()
- public void next()
- public boolean exists()
- public Collection filter()
- public boolean forAll()
- public Collection map()
- public array partition()
- public mixed indexOf()
- public array slice()
- // Inherited methods from Countable
- public int count()
- // Inherited methods from IteratorAggregate
- public Traversable getIterator()
- // Inherited methods from ArrayAccess
- public boolean offsetExists()
- public mixed offsetGet()
- public void offsetSet()
- public void offsetUnset()
Hierarchy
Extends
Implemented by
Methods
public
- add() — Adds an element at the end of the collection.
- clear() — Clears the collection, removing all elements.
- contains() — Checks whether an element is contained in the collection.
- containsKey() — Checks whether the collection contains an element with the specified key/index.
- current() — Gets the element of the collection at the current iterator position.
- exists() — Tests for the existence of an element that satisfies the given predicate.
- filter() — Returns all the elements of this collection that satisfy the predicate p.
- first() — Sets the internal iterator to the first element in the collection and returns this element.
- forAll() — Applies the given predicate p to all elements of this collection, returning true, if the predicate yields true for all elements.
- get() — Gets the element at the specified key/index.
- getKeys() — Gets all keys/indices of the collection.
- getValues() — Gets all values of the collection.
- indexOf() — 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.
- isEmpty() — Checks whether the collection is empty (contains no elements).
- key() — Gets the key/index of the element at the current iterator position.
- last() — Sets the internal iterator to the last element in the collection and returns this element.
- map() — Applies the given function to each element in the collection and returns a new collection with the elements returned by the function.
- next() — Moves the internal iterator position to the next element.
- partition() — Partitions this collection in two collections according to a predicate.
- remove() — Removes the element at the specified index from the collection.
- removeElement() — Removes the specified element from the collection, if it is found.
- set() — Sets an element in the collection at the specified key/index.
- slice() — Extract a slice of $length elements starting at position $offset from the Collection.
- toArray() — Gets a native PHP array representation of the collection.
Inherited from Countable
public
- count() — Count elements of an object
Inherited from IteratorAggregate
public
- getIterator() — Retrieve an external iterator
Inherited from ArrayAccess
public
- offsetExists() — Whether a offset exists
- offsetGet() — Offset to retrieve
- offsetSet() — Offset to set
- offsetUnset() — Offset to unset