Doctrine


Doctrine\Common\Collections\ArrayCollection
/Doctrine/Common/Collections/ArrayCollection.php at line 38

Class ArrayCollection

ArrayCollection

public class ArrayCollection

An ArrayCollection is a Collection implementation that uses a regular PHP array internally.

License:
http://www.opensource.org/licenses/lgpl-license.php LGPL
See Also:
www.doctrine-project.org
Since:
2.0
Version:
$Revision: 3938 $
Author:
Guilherme Blanco
Jonathan Wage
Roman Borschel

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

getIterator()

Gets an iterator for iterating over the elements in the collection.

array

getKeys()

Gets all keys/indexes of the collection elements.

array

getValues()

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.

Constructor Detail

/Doctrine/Common/Collections/ArrayCollection.php at line 53

ArrayCollection

public ArrayCollection(array elements)

Initializes a new ArrayCollection.


Method Detail

/Doctrine/Common/Collections/ArrayCollection.php at line 321

add

public boolean add(mixed value)

Adds an element to the collection.

Returns:
Always TRUE.

/Doctrine/Common/Collections/ArrayCollection.php at line 426

clear

public void clear()

Clears the collection.


/Doctrine/Common/Collections/ArrayCollection.php at line 223

contains

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.

Returns:
TRUE if the given element is contained in the collection, FALSE otherwise.

/Doctrine/Common/Collections/ArrayCollection.php at line 208

containsKey

public boolean containsKey(mixed key)

Checks whether the collection contains a specific key/index.

Parameters:
key - The key to check for.
Returns:
TRUE if the given key/index exists, FALSE otherwise.

/Doctrine/Common/Collections/ArrayCollection.php at line 296

count

public integer count()

Returns the number of elements in the collection.

Implementation of the Countable interface.

Returns:
The number of elements in the collection.

/Doctrine/Common/Collections/ArrayCollection.php at line 115

current

public mixed current()

Gets the element of the collection at the current internal iterator position.


/Doctrine/Common/Collections/ArrayCollection.php at line 234

exists

public boolean exists(Closure p)

Tests for the existance of an element that satisfies the given predicate.

Parameters:
p - The predicate.
Returns:
TRUE if the predicate is TRUE for at least one element, FALSE otherwise.

/Doctrine/Common/Collections/ArrayCollection.php at line 368

filter

public Collection filter(Closure p)

Returns all the elements of this collection that satisfy the predicate p. The order of the elements is preserved.

Parameters:
p - The predicate used for filtering.
Returns:
A collection with the results of the filter operation.

/Doctrine/Common/Collections/ArrayCollection.php at line 74

first

public mixed first()

Sets the internal iterator to the first element in the collection and returns this element.


/Doctrine/Common/Collections/ArrayCollection.php at line 380

forAll

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.

Parameters:
p - The predicate.
Returns:
TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.

/Doctrine/Common/Collections/ArrayCollection.php at line 261

get

public mixed get(mixed key)

Gets the element with the given key/index.

Parameters:
key - The key.
Returns:
The element or NULL, if no element exists for the given key.

/Doctrine/Common/Collections/ArrayCollection.php at line 344

getIterator

public ArrayIterator getIterator()

Gets an iterator for iterating over the elements in the collection.


/Doctrine/Common/Collections/ArrayCollection.php at line 274

getKeys

public array getKeys()

Gets all keys/indexes of the collection elements.


/Doctrine/Common/Collections/ArrayCollection.php at line 284

getValues

public array getValues()

Gets all elements.


/Doctrine/Common/Collections/ArrayCollection.php at line 250

indexOf

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.

Parameters:
element - The element to search for.
Returns:
The key/index of the element or FALSE if the element was not found.

/Doctrine/Common/Collections/ArrayCollection.php at line 334

isEmpty

public boolean isEmpty()

Checks whether the collection is empty.

Note: This is preferrable over count() == 0.

Returns:
TRUE if the collection is empty, FALSE otherwise.

/Doctrine/Common/Collections/ArrayCollection.php at line 95

key

public mixed key()

Gets the current key/index at the current internal iterator position.


/Doctrine/Common/Collections/ArrayCollection.php at line 85

last

public mixed last()

Sets the internal iterator to the last element in the collection and returns this element.


/Doctrine/Common/Collections/ArrayCollection.php at line 356

map

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.


/Doctrine/Common/Collections/ArrayCollection.php at line 105

next

public mixed next()

Moves the internal iterator position to the next element.


/Doctrine/Common/Collections/ArrayCollection.php at line 163

offsetExists

public void offsetExists(mixed offset)

ArrayAccess implementation of offsetExists()

See Also:
containsKey()

/Doctrine/Common/Collections/ArrayCollection.php at line 173

offsetGet

public void offsetGet(mixed offset)

ArrayAccess implementation of offsetGet()

See Also:
get()

/Doctrine/Common/Collections/ArrayCollection.php at line 184

offsetSet

public void offsetSet(mixed offset, mixed value)

ArrayAccess implementation of offsetGet()

See Also:
add()
set()

/Doctrine/Common/Collections/ArrayCollection.php at line 197

offsetUnset

public void offsetUnset(mixed offset)

ArrayAccess implementation of offsetUnset()

See Also:
remove()

/Doctrine/Common/Collections/ArrayCollection.php at line 400

partition

public array partition(Closure p)

Partitions this collection in two collections according to a predicate. Keys are preserved in the resulting collections.

Parameters:
p - The predicate on which to partition.
Returns:
An array with two elements. The first element contains the collection of elements where the predicate returned TRUE, the second element contains the collection of elements where the predicate returned FALSE.

/Doctrine/Common/Collections/ArrayCollection.php at line 126

remove

public mixed remove(mixed key)

Removes an element with a specific key/index from the collection.


/Doctrine/Common/Collections/ArrayCollection.php at line 144

removeElement

public boolean removeElement(mixed element)

Removes the specified element from the collection, if it is found.


/Doctrine/Common/Collections/ArrayCollection.php at line 310

set

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).


/Doctrine/Common/Collections/ArrayCollection.php at line 63

toArray

public array toArray()

Gets the PHP array representation of this collection.

Returns:
The PHP array representation of this collection.

Doctrine