Methods |
public
|
__construct(Arrayable<TKey, TValue>|iterable<TKey, TValue> $items = [])
|
#
|
public
static
|
empty(): static
Get a new collection with no items
Get a new collection with no items
|
#
|
public
|
copy(): static
Get a copy of the collection
Get a copy of the collection
|
#
|
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
|
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<T is TValue|TKey|array{TKey, TValue}>(
callable(T, T|null $next, T|null $prev): mixed $callback,
int-mask-of<CollectionInterface::*> $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<T is TValue|TKey|array{TKey, TValue}, TReturn>(
callable(T, T|null $next, T|null $prev): TReturn $callback,
int-mask-of<CollectionInterface::*> $mode = CollectionInterface::CALLBACK_USE_VALUE,
): static<TKey, TReturn>
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<T is TValue|TKey|array{TKey, TValue}>(
callable(T, T|null $next, T|null $prev): bool $callback,
int-mask-of<CollectionInterface::*> $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<T is TValue|TKey|array{TKey, TValue}>(
callable(T, T|null $next, T|null $prev): bool $callback,
int-mask-of<CollectionInterface::*> $mode = CollectionInterface::CALLBACK_USE_VALUE | CollectionInterface::FIND_VALUE,
): ($mode is 8|9|10|11 ? 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
|
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
|
#
|