Methods |
public
|
__construct(Arrayable<TKey, TValue>|iterable<TKey, TValue> $items = [])
|
#
|
public
|
isEmpty(): bool
Check if the collection is empty
Check if the collection is empty
|
#
|
public
|
set(TKey $key, TValue $value): static
Add or replace an item with a given key
Add or replace an item with a given key
Implemented by
|
#
|
public
|
has(TKey $key): bool
Check if an item with a given key exists
Check if an item with a given key exists
|
#
|
public
|
get(TKey $key): TValue
Get the item with the given key
Get the item with the given key
Throws
|
#
|
public
|
unset(TKey $key): static
Remove an item with a given key
Remove an item with a given key
Implemented by
|
#
|
public
|
add(TValue $value): static
Add an item
|
#
|
public
|
merge(Arrayable<TKey, TValue>|iterable<TKey, TValue> $items): static
Merge the collection with the given items
Merge the collection with the given items
Implemented by
|
#
|
public
|
sort(): static
Sort items in the collection
Sort items in the collection
Implemented by
|
#
|
public
|
reverse(): static
Reverse the order of items in the collection
Reverse the order of items in the collection
Implemented by
|
#
|
public
|
forEach<TMode is int-mask-of<CollectionInterface::*>>(
(TMode is 3|11|19 ? callable(array{TKey, TValue}, array{TKey, TValue}|null $next, array{TKey, TValue}|null $prev): mixed : (TMode is 2|10|18 ? callable(TKey, TKey|null $next, TKey|null $prev): mixed : callable(TValue, TValue|null $next, TValue|null $prev): mixed)) $callback,
TMode $mode = CollectionInterface::CALLBACK_USE_VALUE,
): $this
Pass each item in the collection to a callback
Pass each item in the collection to a callback
The callback's return values are discarded.
|
#
|
public
|
map<TMode is int-mask-of<CollectionInterface::*>>(
(TMode is 3|11|19 ? callable(array{TKey, TValue}, array{TKey, TValue}|null $next, array{TKey, TValue}|null $prev): TValue : (TMode is 2|10|18 ? callable(TKey, TKey|null $next, TKey|null $prev): TValue : callable(TValue, TValue|null $next, TValue|null $prev): TValue)) $callback,
TMode $mode = CollectionInterface::CALLBACK_USE_VALUE,
): static
Pass each item in the collection to a callback and populate a new
collection with its return values
Pass each item in the collection to a callback and populate a new
collection with its return values
Implemented by
|
#
|
public
|
filter<TMode is int-mask-of<CollectionInterface::*>>(
(TMode is 3|11|19 ? callable(array{TKey, TValue}, array{TKey, TValue}|null $next, array{TKey, TValue}|null $prev): bool : (TMode is 2|10|18 ? callable(TKey, TKey|null $next, TKey|null $prev): bool : callable(TValue, TValue|null $next, TValue|null $prev): bool)) $callback,
TMode $mode = CollectionInterface::CALLBACK_USE_VALUE,
): static
Reduce the collection to items that satisfy a callback
Reduce the collection to items that satisfy a callback
Implemented by
|
#
|
public
|
find<TMode is int-mask-of<CollectionInterface::*>>(
(TMode is 3|11|19 ? callable(array{TKey, TValue}, array{TKey, TValue}|null $next, array{TKey, TValue}|null $prev): bool : (TMode is 2|10|18 ? callable(TKey, TKey|null $next, TKey|null $prev): bool : callable(TValue, TValue|null $next, TValue|null $prev): bool)) $callback,
TMode $mode = CollectionInterface::CALLBACK_USE_VALUE | CollectionInterface::FIND_VALUE,
): (TMode is 16|17|18|19 ? TKey : TValue)|null
Get the first item that satisfies a callback, or null if there is no such
item in the collection
Get the first item that satisfies a callback, or null if there is no such
item in the collection
|
#
|
public
|
only(TKey[] $keys): static
Reduce the collection to items with keys in an array
Reduce the collection to items with keys in an array
Implemented by
|
#
|
public
|
onlyIn(array<TKey, true> $index): static
Reduce the collection to items with keys in an index
Reduce the collection to items with keys in an index
Implemented by
|
#
|
public
|
except(TKey[] $keys): static
Reduce the collection to items with keys not in an array
Reduce the collection to items with keys not in an array
Implemented by
|
#
|
public
|
exceptIn(array<TKey, true> $index): static
Reduce the collection to items with keys not in an index
Reduce the collection to items with keys not in an index
Implemented by
|
#
|
public
|
slice(int $offset, ?int $length = null): static
Extract a slice of the collection
Extract a slice of the collection
Implemented by
|
#
|
public
|
hasValue(TValue $value, bool $strict = false): bool
Check if a value is in the collection
Check if a value is in the collection
|
#
|
public
|
keyOf(TValue $value, bool $strict = false): TKey|null
Get the first key at which a value is found, or null if it's not in the
collection
Get the first key at which a value is found, or null if it's not in the
collection
|
#
|
public
|
firstOf(TValue $value): TValue|null
Get the first item equal but not necessarily identical to a value, or
null if it's not in the collection
Get the first item equal but not necessarily identical to a value, or
null if it's not in the collection
|
#
|
public
|
all(): array<TKey, TValue>
Get all items in the collection
Get all items in the collection
|
#
|
public
|
first(): TValue|null
Get the first item, or null if the collection is empty
Get the first item, or null if the collection is empty
|
#
|
public
|
last(): TValue|null
Get the last item, or null if the collection is empty
Get the last item, or null if the collection is empty
|
#
|
public
|
nth(int $n): TValue|null
Get the nth item (1-based), or null if there is no such item in the
collection
Get the nth item (1-based), or null if there is no such item in the
collection
If $n is negative, the nth item from the end of the collection is
returned.
|
#
|
public
|
push(TValue ...$items): static
Push items onto the end of the collection
Push items onto the end of the collection
Implemented by
|
#
|
public
|
pop(TValue|null &$last = null): static
Pop an item off the end of the collection
Pop an item off the end of the collection
Parameters
$last |
Receives the value removed from the collection,
or null if the collection is empty.
|
Implemented by
|
#
|
public
|
shift(TValue|null &$first = null): static
Shift an item off the beginning of the collection
Shift an item off the beginning of the collection
Parameters
$first |
Receives the value removed from the collection,
or null if the collection is empty.
|
Implemented by
|
#
|
public
|
unshift(TValue ...$items): static
Add items to the beginning of the collection
Add items to the beginning of the collection
Items are added in one operation and stay in the given order.
Implemented by
|
#
|