ArrayCollection
public class ArrayCollection
www.doctrine-project.org
Constructor Summary | |
---|---|
ArrayCollection(array elements) Initializes a new ArrayCollection. |
Method Summary | |
---|---|
boolean | add(mixed value) Adds an element to the collection. |
void | clear() Clears the collection. |
boolean | contains(mixed element) Checks whether the given element is contained in the collection. |
boolean | containsKey(mixed key) Checks whether the collection contains a specific key/index. |
integer | count() Returns the number of elements in the collection. |
mixed | current() Gets the element of the collection at the current internal iterator position. |
boolean | exists(Closure p) Tests for the existance of an element that satisfies the given predicate. |
Collection | filter(Closure p) Returns all the elements of this collection that satisfy the predicate p. |
mixed | first() Sets the internal iterator to the first element in the collection and returns this element. |
boolean | forAll(Closure p) Applies the given predicate p to all elements of this collection, returning true, if the predicate yields true for all elements. |
mixed | get(mixed key) Gets the element with the given key/index. |
ArrayIterator | Gets an iterator for iterating over the elements in the collection. |
array | getKeys() Gets all keys/indexes of the collection elements. |
array | Gets all elements. |
mixed | indexOf(mixed element) Searches for a given element and, if found, returns the corresponding key/index of that element. |
boolean | isEmpty() Checks whether the collection is empty. |
mixed | key() Gets the current key/index at the current internal iterator position. |
mixed | last() Sets the internal iterator to the last element in the collection and returns this element. |
Collection | map(Closure func) Applies the given function to each element in the collection and returns a new collection with the elements returned by the function. |
mixed | next() Moves the internal iterator position to the next element. |
void | offsetExists(mixed offset) ArrayAccess implementation of offsetExists() |
void | offsetGet(mixed offset) ArrayAccess implementation of offsetGet() |
void | offsetSet(mixed offset, mixed value) ArrayAccess implementation of offsetGet() |
void | offsetUnset(mixed offset) ArrayAccess implementation of offsetUnset() |
array | partition(Closure p) Partitions this collection in two collections according to a predicate. |
mixed | remove(mixed key) Removes an element with a specific key/index from the collection. |
boolean | removeElement(mixed element) Removes the specified element from the collection, if it is found. |
void | set(mixed key, mixed value) Adds/sets an element in the collection at the index / with the specified key. |
array | toArray() Gets the PHP array representation of this collection. |
public ArrayCollection(array elements)
Initializes a new ArrayCollection.
public boolean add(mixed value)
Adds an element to the collection.
public void clear()
Clears the collection.
public boolean contains(mixed element)
Checks whether the given element is contained in the collection. Only element values are compared, not keys. 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.
public boolean containsKey(mixed key)
Checks whether the collection contains a specific key/index.
public integer count()
Returns the number of elements in the collection.
Implementation of the Countable interface.
public mixed current()
Gets the element of the collection at the current internal iterator position.
public boolean exists(Closure p)
Tests for the existance of an element that satisfies the given predicate.
public Collection filter(Closure p)
Returns all the elements of this collection that satisfy the predicate p. The order of the elements is preserved.
public mixed first()
Sets the internal iterator to the first element in the collection and returns this element.
public boolean forAll(Closure p)
Applies the given predicate p to all elements of this collection, returning true, if the predicate yields true for all elements.
public mixed get(mixed key)
Gets the element with the given key/index.
public ArrayIterator getIterator()
Gets an iterator for iterating over the elements in the collection.
public array getKeys()
Gets all keys/indexes of the collection elements.
public array getValues()
Gets all elements.
public mixed indexOf(mixed element)
Searches for a given element and, if found, returns the corresponding key/index of that 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.
public boolean isEmpty()
Checks whether the collection is empty.
Note: This is preferrable over count() == 0.
public mixed key()
Gets the current key/index at the current internal iterator position.
public mixed last()
Sets the internal iterator to the last element in the collection and returns this element.
public Collection map(Closure func)
Applies the given function to each element in the collection and returns a new collection with the elements returned by the function.
public mixed next()
Moves the internal iterator position to the next element.
public void offsetExists(mixed offset)
ArrayAccess implementation of offsetExists()
public void offsetGet(mixed offset)
ArrayAccess implementation of offsetGet()
public void offsetSet(mixed offset, mixed value)
ArrayAccess implementation of offsetGet()
public void offsetUnset(mixed offset)
ArrayAccess implementation of offsetUnset()
public array partition(Closure p)
Partitions this collection in two collections according to a predicate. Keys are preserved in the resulting collections.
public mixed remove(mixed key)
Removes an element with a specific key/index from the collection.
public boolean removeElement(mixed element)
Removes the specified element from the collection, if it is found.
public void set(mixed key, mixed value)
Adds/sets an element in the collection at the index / with the specified key.
When the collection is a Map this is like put(key,value)/add(key,value). When the collection is a List this is like add(position,value).
public array toArray()
Gets the PHP array representation of this collection.
An ArrayCollection is a Collection implementation that uses a regular PHP array internally.