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.

Methods

void
clear()

Remove all the elements from this array object

toArray()

Returns a native PHP array containing all of the elements in this array object

bool
isEmpty()

Returns true if this array object contains no elements

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

bool
contains(mixed $element)

Returns true if this collection contains the specified element

string
getType()

Returns the type associated with this collection

bool
remove(mixed $element)

Removes a single instance of the specified element from this collection, if it is present

Details

void clear()

Remove all the elements from this array object

Return Value

void

toArray()

Returns a native PHP array containing all of the elements in this array object

bool isEmpty()

Returns true if this array object contains no elements

Return Value

bool

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.

Parameters

mixed $element

Return Value

bool true if this collection changed as a result of the call

bool contains(mixed $element)

Returns true if this collection contains the specified element

This performs a strict type check on the value.

Parameters

mixed $element

Return Value

bool

string getType()

Returns the type associated with this collection

Return Value

string

bool remove(mixed $element)

Removes a single instance of the specified element from this collection, if it is present

Parameters

mixed $element

Return Value

bool true if an element was removed as a result of this call