CollectionInterface
extends
ArrayAccess, JsonSerializable, IteratorAggregate, Countable
in
Contract for a keyed collection of items. The reference implementation is {@see CollectionTrait}; see {@see ExCollectionInterface} for the extended (array-helper) surface.
Table of Contents
Methods
- __debugInfo() : array<string|int, mixed>
- Debug representation for `var_dump()`.
- __serialize() : array<string|int, mixed>
- The items, for PHP's native `serialize()`.
- __unserialize() : void
- Restores the collection from the payload of PHP's native `unserialize()`.
- clear() : void
- Removes every item from the collection.
- count() : int
- fill() : self
- Fills the collection with an array (or another collection) of items.
- filter() : mixed
- Runs a filter callback over the collection and returns a new collection of the items for which it returned true.
- find() : mixed
- Returns the first item for which `$callback` returns true, or null.
- first() : mixed
- get() : mixed
- Gets an item from the collection whose `$discrim` property equals `$key`.
- getIterator() : Traversable
- has() : bool
- Whether an item exists at every one of `$keys`.
- isset() : bool
- Whether an item exists at `$offset`.
- jsonSerialize() : array<string|int, mixed>
- last() : mixed
- map() : mixed
- Returns a new collection with `$callback` applied to each item.
- merge() : self
- Merges another collection (or array) into this one.
- offsetExists() : bool
- offsetGet() : mixed
- offsetSet() : void
- offsetUnset() : void
- pull() : mixed
- Removes an item at `$key` and returns it, or `$default` when it is absent.
- push() : self
- Pushes one or more items onto the collection.
- pushItem() : self
- Pushes a single item onto the collection, keyed by its discriminator.
- serialize() : string
- Serialises the collection to a JSON string.
- set() : mixed
- Sets a value in the collection at `$offset`.
- toArray() : array<string|int, mixed>
- unserialize() : void
- Restores the collection from a JSON string produced by {@see serialize()}.
Methods
__debugInfo()
Debug representation for `var_dump()`.
public
__debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>__serialize()
The items, for PHP's native `serialize()`.
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__unserialize()
Restores the collection from the payload of PHP's native `unserialize()`.
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
clear()
Removes every item from the collection.
public
clear() : void
count()
public
count() : int
Tags
Return values
intfill()
Fills the collection with an array (or another collection) of items.
public
fill(CollectionInterface|array<string|int, mixed> $items) : self
Parameters
- $items : CollectionInterface|array<string|int, mixed>
Return values
selffilter()
Runs a filter callback over the collection and returns a new collection of the items for which it returned true.
public
filter(callable $callback) : mixed
Parameters
- $callback : callable
find()
Returns the first item for which `$callback` returns true, or null.
public
find(callable $callback) : mixed
Parameters
- $callback : callable
first()
public
first() : mixed
Return values
mixed —The first item in the collection, or null when empty.
get()
Gets an item from the collection whose `$discrim` property equals `$key`.
public
get(string $discrim, mixed $key) : mixed
Parameters
- $discrim : string
-
The property to match on.
- $key : mixed
-
The value to match.
Return values
mixed —The matching item, or null.
getIterator()
public
getIterator() : Traversable
Tags
Return values
Traversablehas()
Whether an item exists at every one of `$keys`.
public
has(mixed ...$keys) : bool
Parameters
- $keys : mixed
Return values
boolisset()
Whether an item exists at `$offset`.
public
isset(mixed $offset) : bool
Parameters
- $offset : mixed
Return values
booljsonSerialize()
public
jsonSerialize([bool $assoc = true ]) : array<string|int, mixed>
Parameters
- $assoc : bool = true
-
Whether to keep string keys.
Tags
Return values
array<string|int, mixed>last()
public
last() : mixed
Return values
mixed —The last item in the collection, or null when empty.
map()
Returns a new collection with `$callback` applied to each item.
public
map(callable $callback) : mixed
Parameters
- $callback : callable
merge()
Merges another collection (or array) into this one.
public
merge(CollectionInterface|array<string|int, mixed> $collection) : self
Parameters
- $collection : CollectionInterface|array<string|int, mixed>
Return values
selfoffsetExists()
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Tags
Return values
booloffsetGet()
public
offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
Tags
Attributes
- #[ReturnTypeWillChange]
offsetSet()
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
Tags
offsetUnset()
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
Tags
pull()
Removes an item at `$key` and returns it, or `$default` when it is absent.
public
pull(mixed $key[, mixed $default = null ]) : mixed
Parameters
- $key : mixed
- $default : mixed = null
push()
Pushes one or more items onto the collection.
public
push(mixed ...$items) : self
Parameters
- $items : mixed
Return values
selfpushItem()
Pushes a single item onto the collection, keyed by its discriminator.
public
pushItem(mixed $item) : self
Parameters
- $item : mixed
Return values
selfserialize()
Serialises the collection to a JSON string.
public
serialize([int $flags = 0 ][, int|null $depth = 512 ]) : string
Parameters
- $flags : int = 0
-
json_encodeflags. - $depth : int|null = 512
-
json_encodedepth.
Return values
stringset()
Sets a value in the collection at `$offset`.
public
set(mixed $offset, mixed $value) : mixed
Parameters
- $offset : mixed
- $value : mixed
toArray()
public
toArray([bool $assoc = true ]) : array<string|int, mixed>
Use jsonSerialize
Parameters
- $assoc : bool = true
-
Whether to keep string keys.
Return values
array<string|int, mixed>unserialize()
Restores the collection from a JSON string produced by {@see serialize()}.
public
unserialize(string $serialized) : void
Parameters
- $serialized : string