Documentation

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
psalm-template

TKey of array-key

psalm-template

T

template-implements

Collection<TKey,T>

template-implements

Selectable<TKey,T>

psalm-consistent-constructor

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
psalm-var

array<TKey,T>

Methods

__construct()

Initializes a new ArrayCollection.

public __construct([array<string|int, mixed> $elements = [] ]) : mixed
Parameters
$elements : array<string|int, mixed> = []
Tags
psalm-param

array<TKey,T> $elements

__toString()

Returns a string representation of this object.

public __toString() : string
Return values
string

add()

Adds an element at the end of the collection.

public add(mixed $element) : true
Parameters
$element : mixed

The element to add.

Tags
psalm-suppress

InvalidPropertyAssignmentValue

This breaks assumptions about the template type, but it would be a backwards-incompatible change to remove this method

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
template

TMaybeContained

containsKey()

{@inheritDoc}

public containsKey(mixed $key) : mixed
Parameters
$key : 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
psalm-return

static<TKey,T>

Return values
static

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
psalm-return

Traversable<TKey,T>

Return values
Traversable<int|string, mixed>

indexOf()

{@inheritDoc}

public indexOf(mixed $element) : mixed
Parameters
$element : mixed
Tags
psalm-param

TMaybeContained $element

psalm-return

(TMaybeContained is T ? TKey|false : false)

template

TMaybeContained

map()

{@inheritDoc}

public map(Closure $func) : static
Parameters
$func : Closure
Tags
psalm-param

Closure(T):U $func

psalm-return

static<TKey, U>

psalm-template

U

Return values
static

offsetExists()

Required by interface ArrayAccess.

public offsetExists(TKey $offset) : bool
Parameters
$offset : TKey
Return values
bool

offsetGet()

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

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.

Tags
psalm-param

array<K,V> $elements

psalm-return

static<K,V>

psalm-template

K of array-key

psalm-template

V

Return values
static

        
On this page

Search results