ExCollectionInterface
extends
CollectionInterface
in
The extended collection contract: {@see CollectionInterface} plus the array-style helpers (`shift`, `search`, `splice`, `slice`, `sort`, `diff`, `intersect`, `walk`, `reduce`, `unique`, …). Implemented by {@see CollectionTrait}.
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()`.
- all() : bool
- Whether every item matches `$callback`.
- any() : bool
- Whether at least one item matches `$callback`.
- clear() : void
- Removes every item from the collection.
- count() : int
- diff() : ExCollectionInterface
- 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.
- find_key() : string|int|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`.
- intersect() : ExCollectionInterface
- isset() : bool
- Whether an item exists at `$offset`.
- jsonSerialize() : array<string|int, mixed>
- keys() : 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.
- reduce() : mixed
- search() : string|int|false
- Searches for `$needle` and returns its key, or false when not found.
- serialize() : string
- Serialises the collection to a JSON string.
- set() : mixed
- Sets a value in the collection at `$offset`.
- shift() : array<string|int, mixed>|null
- slice() : ExCollectionInterface
- Returns a new collection with the slice `$offset`..`$offset + $length`.
- sort() : ExCollectionInterface
- splice() : ExCollectionInterface
- Removes `$length` items starting at `$offset`, inserting `$replacement` in their place. Mutates the collection and returns it.
- toArray() : array<string|int, mixed>
- unique() : ExCollectionInterface
- unserialize() : void
- Restores the collection from a JSON string produced by {@see serialize()}.
- values() : array<string|int, mixed>
- walk() : ExCollectionInterface
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>
all()
Whether every item matches `$callback`.
public
all(callable $callback) : bool
Parameters
- $callback : callable
Return values
boolany()
Whether at least one item matches `$callback`.
public
any(callable $callback) : bool
Parameters
- $callback : callable
Return values
boolclear()
Removes every item from the collection.
public
clear() : void
Tags
count()
public
count() : int
Tags
Return values
intdiff()
public
diff(mixed $items[, callable|null $callback = null ]) : ExCollectionInterface
Parameters
- $items : mixed
- $callback : callable|null = null
Return values
ExCollectionInterfacefill()
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
find_key()
public
find_key(callable $callback) : string|int|null
Parameters
- $callback : callable
Return values
string|int|null —The key of the first item matching $callback, or null.
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
boolintersect()
public
intersect(mixed $items[, callable|null $callback = null ]) : ExCollectionInterface
Parameters
- $items : mixed
- $callback : callable|null = null
Return values
ExCollectionInterfaceisset()
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>keys()
public
keys() : array<string|int, mixed>
Return values
array<string|int, mixed> —The collection's keys.
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
selfreduce()
public
reduce(callable $callback[, mixed $initial = null ]) : mixed
Parameters
- $callback : callable
- $initial : mixed = null
Return values
mixed —The final value of $carry.
search()
Searches for `$needle` and returns its key, or false when not found.
public
search(mixed $needle[, bool $strict = false ]) : string|int|false
Parameters
- $needle : mixed
- $strict : bool = false
-
Whether to compare with
===.
Return values
string|int|falseserialize()
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
shift()
public
shift() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —The [key => value] pair removed from the front, or null when the collection is empty.
slice()
Returns a new collection with the slice `$offset`..`$offset + $length`.
public
slice(int $offset[, int|null $length = null ][, bool $preserve_keys = false ]) : ExCollectionInterface
Parameters
- $offset : int
- $length : int|null = null
- $preserve_keys : bool = false
Return values
ExCollectionInterfacesort()
public
sort([callable|int|null $callback = null ]) : ExCollectionInterface
Parameters
- $callback : callable|int|null = null
Return values
ExCollectionInterfacesplice()
Removes `$length` items starting at `$offset`, inserting `$replacement` in their place. Mutates the collection and returns it.
public
splice(int $offset, int|null $length[, mixed $replacement = [] ]) : ExCollectionInterface
Parameters
- $offset : int
- $length : int|null
- $replacement : mixed = []
Return values
ExCollectionInterfacetoArray()
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>unique()
public
unique([int $flags = SORT_STRING ]) : ExCollectionInterface
Parameters
- $flags : int = SORT_STRING
Return values
ExCollectionInterfaceunserialize()
Restores the collection from a JSON string produced by {@see serialize()}.
public
unserialize(string $serialized) : void
Parameters
- $serialized : string
values()
public
values() : array<string|int, mixed>
Return values
array<string|int, mixed> —The collection's values, re-indexed.
walk()
public
walk(callable $callback[, mixed $arg = null ]) : ExCollectionInterface
Parameters
- $callback : callable
- $arg : mixed = null