Methods |
public
static
|
pluck(iterable<mixed[]> $array, string $value, ?string $key = null): ($key is null ? list<mixed> : mixed[])
Get values from a list of arrays using dot notation
Get values from a list of arrays using dot notation
|
#
|
public
static
|
get(mixed[] $array, string $key, mixed $default = null): mixed
Get a value from an array using dot notation
Get a value from an array using dot notation
Throws
|
#
|
public
static
|
has(mixed[] $array, string $key): bool
Check if a value exists in an array using dot notation
Check if a value exists in an array using dot notation
|
#
|
public
static
|
first<TValue>(TValue[] $array): ($array is non-empty-array ? TValue : null)
Get the first value in an array
Get the first value in an array
|
#
|
public
static
|
last<TValue>(TValue[] $array): ($array is non-empty-array ? TValue : null)
Get the last value in an array
Get the last value in an array
|
#
|
public
static
|
keyOf<TKey is array-key, TValue>(array<TKey, TValue> $array, TValue $value, bool $strict = true): TKey
Get the key of a value in an array
Get the key of a value in an array
Throws
|
#
|
public
static
|
search<TKey is array-key, TValue>(array<TKey, TValue> $array, TValue $value, bool $strict = true): TKey|null
Get the key of a value in an array, or null if it is not found
Get the key of a value in an array, or null if it is not found
|
#
|
public
static
|
combine<TKey is array-key, TValue>(TKey[] $keys, TValue[] $values): array<TKey, TValue>
Get an array comprised of the given keys and values
Get an array comprised of the given keys and values
|
#
|
public
static
|
shift<TKey is array-key, TValue>(array<TKey, TValue> $array, TValue|null &$shifted = null): array<TKey, TValue>
Shift an element off the beginning of an array
Shift an element off the beginning of an array
|
#
|
public
static
|
unshift<TKey is array-key, TValue>(array<TKey, TValue> $array, TValue ...$values): array<TKey|int, TValue>
Add elements to the beginning of an array
Add elements to the beginning of an array
|
#
|
public
static
|
pop<TKey is array-key, TValue>(array<TKey, TValue> $array, TValue|null &$popped = null): array<TKey, TValue>
Pop a value off the end of an array
Pop a value off the end of an array
|
#
|
public
static
|
push<TKey is array-key, TValue>(array<TKey, TValue> $array, TValue ...$values): array<TKey|int, TValue>
Push values onto the end of an array
Push values onto the end of an array
|
#
|
public
static
|
extend<TKey is array-key, TValue>(array<TKey, TValue> $array, TValue ...$values): array<TKey|int, TValue>
Push values onto the end of an array after excluding any that are already
present
Push values onto the end of an array after excluding any that are already
present
|
#
|
public
static
|
set<TKey is array-key, TValue>(array<TKey, TValue> $array, TKey $key, TValue $value): array<TKey, TValue>
Assign a value to an element of an array
Assign a value to an element of an array
|
#
|
public
static
|
setIf<TKey is array-key, TValue>(array<TKey, TValue> $array, TKey $key, TValue $value): array<TKey, TValue>
Assign a value to an element of an array if it isn't already set
Assign a value to an element of an array if it isn't already set
|
#
|
public
static
|
unset<TKey is array-key, TValue>(array<TKey, TValue> $array, TKey ...$keys): array<TKey, TValue>
Remove keys from an array
Remove keys from an array
|
#
|
public
static
|
sort<TKey is array-key, TValue>(
array<TKey, TValue> $array,
bool $preserveKeys = false,
(callable(TValue, TValue): int)|int-mask-of<Arr::SORT_*> $callbackOrFlags = SORT_REGULAR,
): ($preserveKeys is true ? array<TKey, TValue> : list<TValue>)
Sort an array by value
|
#
|
public
static
|
sortDesc<TKey is array-key, TValue>(
array<TKey, TValue> $array,
bool $preserveKeys = false,
int-mask-of<Arr::SORT_*> $flags = SORT_REGULAR,
): ($preserveKeys is true ? array<TKey, TValue> : list<TValue>)
Sort an array by value in descending order
Sort an array by value in descending order
|
#
|
public
static
|
sortByKey<TKey is array-key, TValue>(
array<TKey, TValue> $array,
(callable(TKey, TKey): int)|int-mask-of<Arr::SORT_*> $callbackOrFlags = SORT_REGULAR,
): array<TKey, TValue>
Sort an array by key
|
#
|
public
static
|
sortByKeyDesc<TKey is array-key, TValue>(
array<TKey, TValue> $array,
int-mask-of<Arr::SORT_*> $flags = SORT_REGULAR,
): array<TKey, TValue>
Sort an array by key in descending order
Sort an array by key in descending order
|
#
|
public
static
|
unique<TKey, TValue>(
iterable<TKey, TValue> $array,
bool $preserveKeys = false,
bool $strict = true,
): ($preserveKeys is true ? (TKey is array-key ? ($array is non-empty-array ? non-empty-array<TKey, TValue> : array<TKey, TValue>) : ($array is non-empty-array ? non-empty-array<array-key, TValue> : array<array-key, TValue>)) : ($array is non-empty-array ? non-empty-list<TValue> : list<TValue>))
Remove duplicate values from an array
Remove duplicate values from an array
|
#
|
public
static
|
isList(mixed $value, bool $orEmpty = false): bool
Check if a value is an array with integer keys numbered consecutively
from 0
Check if a value is an array with integer keys numbered consecutively
from 0
|
#
|
public
static
|
isIndexed(mixed $value, bool $orEmpty = false): bool
Check if a value is an array with integer keys
Check if a value is an array with integer keys
|
#
|
public
static
|
ofArrayKey(mixed $value, bool $orEmpty = false): bool
Check if a value is an array of integers or an array of strings
Check if a value is an array of integers or an array of strings
|
#
|
public
static
|
ofInt(mixed $value, bool $orEmpty = false): bool
Check if a value is an array of integers
Check if a value is an array of integers
|
#
|
public
static
|
ofString(mixed $value, bool $orEmpty = false): bool
Check if a value is an array of strings
Check if a value is an array of strings
|
#
|
public
static
|
of<T>(mixed $value, class-string<T> $class, bool $orEmpty = false): bool
Check if a value is an array of instances of a given class
Check if a value is an array of instances of a given class
|
#
|
public
static
|
sameValues(mixed[] $array1, mixed[] $array2, mixed[] ...$arrays): bool
Check if arrays have the same values after sorting for comparison
Check if arrays have the same values after sorting for comparison
|
#
|
public
static
|
same(mixed[] $array1, mixed[] $array2, mixed[] ...$arrays): bool
Check if arrays are the same after sorting by key
Check if arrays are the same after sorting by key
|
#
|
public
static
|
whereNotNull<TKey, TValue>(
iterable<TKey, TValue|null> $array,
): (TKey is array-key ? array<TKey, TValue> : array<array-key, TValue>)
Remove null values from an array
Remove null values from an array
|
#
|
public
static
|
whereNotEmpty<TKey, TValue is int|float|string|bool|Stringable>(
iterable<TKey, TValue|null> $array,
): (TKey is array-key ? array<TKey, TValue> : array<array-key, TValue>)
Remove empty strings from an array of strings and Stringables
Remove empty strings from an array of strings and Stringables
|
#
|
public
static
|
implode(
string $separator,
iterable<int|float|string|bool|Stringable|null> $array,
string|null $characters = null,
): string
Implode values that remain in an array of strings and Stringables after
trimming characters from each value and…
Implode values that remain in an array of strings and Stringables after
trimming characters from each value and removing empty strings
Parameters
$characters |
Characters to trim, null (the default)
to trim whitespace, or an empty string to trim nothing.
|
|
#
|
public
static
|
trim<TKey>(
iterable<TKey, int|float|string|bool|Stringable|null> $array,
string|null $characters = null,
bool $removeEmpty = true,
bool $nullEmpty = false,
): ($removeEmpty is false ? ($nullEmpty is true ? (TKey is array-key ? array<TKey, string|null> : array<array-key, string|null>) : (TKey is array-key ? array<TKey, string> : array<array-key, string>)) : list<string>)
Trim characters from each value in an array of strings and Stringables
before removing or optionally replacing empty…
Trim characters from each value in an array of strings and Stringables
before removing or optionally replacing empty strings
Parameters
$characters |
Characters to trim, null (the default)
to trim whitespace, or an empty string to trim nothing.
|
|
#
|
public
static
|
lower<TKey, TValue is int|float|string|bool|Stringable|null>(
iterable<TKey, TValue> $array,
): (TKey is array-key ? array<TKey, string> : array<array-key, string>)
Make an array of strings and Stringables lowercase
Make an array of strings and Stringables lowercase
|
#
|
public
static
|
upper<TKey, TValue is int|float|string|bool|Stringable|null>(
iterable<TKey, TValue> $array,
): (TKey is array-key ? array<TKey, string> : array<array-key, string>)
Make an array of strings and Stringables uppercase
Make an array of strings and Stringables uppercase
|
#
|
public
static
|
snakeCase<TKey, TValue is int|float|string|bool|Stringable|null>(
iterable<TKey, TValue> $array,
): (TKey is array-key ? array<TKey, string> : array<array-key, string>)
Make an array of strings and Stringables snake_case
Make an array of strings and Stringables snake_case
|
#
|
public
static
|
toScalars<TKey, TValue is int|float|string|bool, TNull is int|float|string|bool|null>(
iterable<TKey, TValue|mixed[]|object|null> $array,
TNull $null = null,
): (TKey is array-key ? array<TKey, TValue|TNull|string> : array<array-key, TValue|TNull|string>)
Cast non-scalar values in an array to strings
Cast non-scalar values in an array to strings
Objects that implement {@see Stringable} are cast to a string. null
values are replaced with $null . Other non-scalar values are
JSON-encoded.
|
#
|
public
static
|
toStrings<TKey, TNull is string|null>(
iterable<TKey, mixed[]|object|int|float|string|bool|null> $array,
TNull $null = null,
): (TKey is array-key ? array<TKey, TNull|string> : array<array-key, TNull|string>)
Cast values in an array to strings
Cast values in an array to strings
Scalar values and objects that implement {@see Stringable} are cast to a
string. null values are replaced with $null . Other non-scalar values
are JSON-encoded.
|
#
|
public
static
|
offsetOfKey<TKey is array-key>(array<TKey, mixed> $array, TKey $key): int
Get the offset (0-based) of a key in an array
Get the offset (0-based) of a key in an array
Throws
|
#
|
public
static
|
rename<TKey is array-key, TValue>(array<TKey, TValue> $array, TKey $key, TKey $newKey): array<TKey, TValue>
Rename an array key without changing its offset
Rename an array key without changing its offset
Throws
|
#
|
public
static
|
splice<TKey is array-key, TValue>(
array<TKey, TValue> $array,
int $offset,
?int $length = null,
TValue[]|TValue $replacement = [],
array<TKey, TValue>|null &$replaced = null,
): array<TKey|int, TValue>
Remove and/or replace part of an array by offset (0-based)
Remove and/or replace part of an array by offset (0-based)
|
#
|
public
static
|
spliceByKey<TKey is array-key, TValue>(
array<TKey, TValue> $array,
TKey $key,
?int $length = null,
array<TKey, TValue> $replacement = [],
array<TKey, TValue>|null &$replaced = null,
): array<TKey, TValue>
Remove and/or replace part of an array by key
Remove and/or replace part of an array by key
Throws
|
#
|
public
static
|
toIndex<TKey is array-key, TValue>(
iterable<TKey> $array,
TValue $value = true,
): ($value is true ? array<TKey, true> : array<TKey, TValue>)
Get an array that maps the values in an array to a given value
Get an array that maps the values in an array to a given value
|
#
|
public
static
|
toMap<TValue is ArrayAccess|mixed[]|object>(iterable<TValue> $array, array-key $key): TValue[]
Index an array by an identifier unique to each value
Index an array by an identifier unique to each value
|
#
|
public
static
|
with<TKey, TValue, T>(iterable<TKey, TValue> $array, callable(T, TValue, TKey): T $callback, T $value): T
Apply a callback to a value for each of the elements of an array
Apply a callback to a value for each of the elements of an array
The return value of each call is passed to the next or returned to the
caller.
Similar to {@see array_reduce()}.
|
#
|
public
static
|
flatten(iterable<mixed> $array, int $limit = -1): mixed[]
Flatten a multi-dimensional array
Flatten a multi-dimensional array
Parameters
$limit |
The maximum number of dimensions to flatten, or -1
for no limit.
|
|
#
|
public
static
|
wrap<T>(T $value): (T is null ? array{} : (T is array ? T : array{T}))
If a value is not an array, wrap it in one
If a value is not an array, wrap it in one
|
#
|
public
static
|
wrapList<T>(T $value): (T is null ? array{} : (T is list ? T : array{T}))
If a value is not a list, wrap it in one
If a value is not a list, wrap it in one
|
#
|
public
static
|
unwrap(mixed $value, int $limit = -1): mixed
Remove arrays wrapped around a value
Remove arrays wrapped around a value
Parameters
$limit |
The maximum number of arrays to remove, or -1 for no
limit.
|
|
#
|