ArrayCollection
in package
implements
Collection, Selectable
An ArrayCollection is a Collection implementation that wraps a regular PHP array.
Warning: Using (un-)serialize() on a collection is not a supported use-case and may break when we change the internals in the future. If you need to serialize a collection use and reconstruct the collection manually.
Tags
Table of Contents
Interfaces
- Collection
- The missing (SPL) Collection/Array/OrderedMap interface.
- Selectable
- Interface for collections that allow efficient filtering with an expression API.
Properties
- $elements : array<string|int, mixed>
- An array containing the entries of this collection.
Methods
- __construct() : mixed
- Initializes a new ArrayCollection.
- __toString() : string
- Returns a string representation of this object.
- add() : true
- Adds an element at the end of the collection.
- clear() : void
- Clears the collection, removing all elements.
- contains() : mixed
- {@inheritDoc}
- containsKey() : mixed
- {@inheritDoc}
- count() : int
- {@inheritDoc}
- current() : mixed
- {@inheritDoc}
- exists() : mixed
- {@inheritDoc}
- filter() : static
- Returns all the elements of this collection that satisfy the predicate p.
- first() : mixed
- {@inheritDoc}
- forAll() : mixed
- {@inheritDoc}
- get() : mixed
- {@inheritDoc}
- getIterator() : Traversable<int|string, mixed>
- {@inheritDoc}
- getKeys() : mixed
- {@inheritDoc}
- getValues() : mixed
- {@inheritDoc}
- indexOf() : mixed
- {@inheritDoc}
- isEmpty() : mixed
- {@inheritDoc}
- key() : mixed
- {@inheritDoc}
- last() : mixed
- {@inheritDoc}
- map() : static
- {@inheritDoc}
- matching() : Collection<string|int, mixed>|Selectable<string|int, mixed>
- Selects all elements from a selectable that match the expression and returns a new collection containing these elements.
- next() : mixed
- {@inheritDoc}
- offsetExists() : bool
- Required by interface ArrayAccess.
- offsetGet() : mixed
- Required by interface ArrayAccess.
- offsetSet() : void
- Required by interface ArrayAccess.
- offsetUnset() : void
- Required by interface ArrayAccess.
- partition() : array<string|int, Collection<string|int, mixed>>
- Partitions this collection in two collections according to a predicate.
- remove() : mixed
- Removes the element at the specified index from the collection.
- removeElement() : bool
- Removes the specified element from the collection, if it is found.
- set() : void
- Sets an element in the collection at the specified key/index.
- slice() : mixed
- {@inheritDoc}
- toArray() : mixed
- {@inheritDoc}
- createFrom() : static
- Creates a new instance from the specified elements.
Properties
$elements
An array containing the entries of this collection.
private
array<string|int, mixed>
$elements
Tags
Methods
__construct()
Initializes a new ArrayCollection.
public
__construct([array<string|int, mixed> $elements = [] ]) : mixed
Parameters
- $elements : array<string|int, mixed> = []
Tags
__toString()
Returns a string representation of this object.
public
__toString() : string
Return values
stringadd()
Adds an element at the end of the collection.
public
add(mixed $element) : true
Parameters
- $element : mixed
-
The element to add.
Tags
Return values
true —Always TRUE.
clear()
Clears the collection, removing all elements.
public
clear() : void
contains()
{@inheritDoc}
public
contains(mixed $element) : mixed
Parameters
- $element : mixed
Tags
containsKey()
{@inheritDoc}
public
containsKey(mixed $key) : mixed
Parameters
- $key : mixed
count()
{@inheritDoc}
public
count() : int
Return values
intcurrent()
{@inheritDoc}
public
current() : mixed
exists()
{@inheritDoc}
public
exists(Closure $p) : mixed
Parameters
- $p : Closure
filter()
Returns all the elements of this collection that satisfy the predicate p.
public
filter(Closure $p) : static
Parameters
- $p : Closure
-
The predicate used for filtering.
Tags
Return values
staticfirst()
{@inheritDoc}
public
first() : mixed
forAll()
{@inheritDoc}
public
forAll(Closure $p) : mixed
Parameters
- $p : Closure
get()
{@inheritDoc}
public
get(mixed $key) : mixed
Parameters
- $key : mixed
getIterator()
{@inheritDoc}
public
getIterator() : Traversable<int|string, mixed>
Tags
Return values
Traversable<int|string, mixed>getKeys()
{@inheritDoc}
public
getKeys() : mixed
getValues()
{@inheritDoc}
public
getValues() : mixed
indexOf()
{@inheritDoc}
public
indexOf(mixed $element) : mixed
Parameters
- $element : mixed
Tags
isEmpty()
{@inheritDoc}
public
isEmpty() : mixed
key()
{@inheritDoc}
public
key() : mixed
last()
{@inheritDoc}
public
last() : mixed
map()
{@inheritDoc}
public
map(Closure $func) : static
Parameters
- $func : Closure
Tags
Return values
staticmatching()
Selects all elements from a selectable that match the expression and returns a new collection containing these elements.
public
matching(Criteria $criteria) : Collection<string|int, mixed>|Selectable<string|int, mixed>
Parameters
- $criteria : Criteria
Return values
Collection<string|int, mixed>|Selectable<string|int, mixed>next()
{@inheritDoc}
public
next() : mixed
offsetExists()
Required by interface ArrayAccess.
public
offsetExists(TKey $offset) : bool
Parameters
- $offset : TKey
Return values
booloffsetGet()
Required by interface ArrayAccess.
public
offsetGet(TKey $offset) : mixed
Parameters
- $offset : TKey
offsetSet()
Required by interface ArrayAccess.
public
offsetSet(TKey|null $offset, T $value) : void
Parameters
- $offset : TKey|null
- $value : T
offsetUnset()
Required by interface ArrayAccess.
public
offsetUnset(TKey $offset) : void
Parameters
- $offset : TKey
partition()
Partitions this collection in two collections according to a predicate.
public
partition(Closure $p) : array<string|int, Collection<string|int, mixed>>
Parameters
- $p : Closure
-
The predicate on which to partition.
Return values
array<string|int, Collection<string|int, mixed>> —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.
remove()
Removes the element at the specified index from the collection.
public
remove(mixed $key) : mixed
Parameters
- $key : mixed
-
The key/index of the element to remove.
Return values
mixed —The removed element or NULL, if the collection did not contain the element.
removeElement()
Removes the specified element from the collection, if it is found.
public
removeElement(mixed $element) : bool
Parameters
- $element : mixed
-
The element to remove.
Return values
bool —TRUE if this collection contained the specified element, FALSE otherwise.
set()
Sets an element in the collection at the specified key/index.
public
set(mixed $key, mixed $value) : void
Parameters
- $key : mixed
-
The key/index of the element to set.
- $value : mixed
-
The element to set.
slice()
{@inheritDoc}
public
slice(mixed $offset[, mixed $length = null ]) : mixed
Parameters
- $offset : mixed
- $length : mixed = null
toArray()
{@inheritDoc}
public
toArray() : mixed
createFrom()
Creates a new instance from the specified elements.
protected
createFrom(array<string|int, mixed> $elements) : static
This method is provided for derived classes to specify how a new instance should be created when constructor semantics have changed.
Parameters
- $elements : array<string|int, mixed>
-
Elements.