class Arr (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable

Methods

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

static bool
accessible(mixed $value)

Determine whether the given value is array accessible.

static JsonSerializable ? true : false)))))
arrayable(mixed $value)

Determine whether the given value is arrayable.

static array
add(array $array, string|int|float $key, mixed $value)

Add an element to an array using "dot" notation if it doesn't exist.

static array
array(ArrayAccess|array $array, string|int|null $key, array|null $default = null)

Get an array item from an array using "dot" notation.

static bool
boolean(ArrayAccess|array $array, string|int|null $key, bool|null $default = null)

Get a boolean item from an array using "dot" notation.

static array
collapse(iterable $array)

Collapse an array of arrays into a single array.

static TValue>>
crossJoin(TValue> ...$arrays)

Cross join the given arrays, returning all possible permutations.

static TValue[]}
divide(TValue> $array)

Divide an array into two arrays. One with keys and the other with values.

static array
dot(iterable $array, string $prepend = '', int $depth = INF)

Flatten a multi-dimensional associative array with dots.

static array
undot(iterable $array)

Convert a flatten "dot" notation array into an expanded array.

static array
except(array $array, array|string|int|float $keys)

Get all of the given array except for a specified array of keys.

static array
exceptValues(array $array, mixed $values, bool $strict = false)

Get all of the given array except for a specified array of values.

static bool
exists(ArrayAccess|array $array, string|int|float $key)

Determine if the given key exists in the provided array.

static TValue|TFirstDefault
first(TValue> $array, callable|null $callback = null, TFirstDefault|TFirstDefault $default = null)

Return the first element in an iterable passing a given truth test.

static TValue|TLastDefault
last(TValue> $array, callable|null $callback = null, TLastDefault|TLastDefault $default = null)

Return the last element in an array passing a given truth test.

static array
take(array $array, int $limit)

Take the first or last {$limit} items from an array.

static array
flatten(iterable $array, int $depth = INF)

Flatten a multi-dimensional array into a single level.

static float
float(ArrayAccess|array $array, string|int|null $key, float|null $default = null)

Get a float item from an array using "dot" notation.

static void
forget(array $array, array|string|int|float $keys)

Remove one or many array items from a given array using "dot" notation.

static TValue>)
from(TValue>|TValue>|TValue>|TValue>|TValue>|Jsonable|JsonSerializable|object $items)

Get the underlying array of items from the given argument.

static mixed
get(ArrayAccess|array $array, string|int|null $key, mixed $default = null)

Get an item from an array using "dot" notation.

static bool
has(ArrayAccess|array $array, string|array $keys)

Check if an item or items exist in an array using "dot" notation.

static bool
hasAll(ArrayAccess|array $array, string|array $keys)

Determine if all keys exist in an array using "dot" notation.

static bool
hasAny(ArrayAccess|array $array, string|array $keys)

Determine if any of the keys exist in an array using "dot" notation.

static bool
every(iterable $array, callable $callback)

Determine if all items pass the given truth test.

static bool
some(iterable $array, callable $callback)

Determine if some items pass the given truth test.

static int
integer(ArrayAccess|array $array, string|int|null $key, int|null $default = null)

Get an integer item from an array using "dot" notation.

static ($array is list ? false : true)
isAssoc(array $array)

Determines if an array is associative.

static ($array is list ? true : false)
isList(array $array)

Determines if an array is a list.

static string
join(array $array, string $glue, string $finalGlue = '')

Join all items using a string. The final items can use a separate glue string.

static array
keyBy(iterable $array, callable|array|string $keyBy)

Key an associative array by a field or using a callback.

static array
prependKeysWith(array $array, string $prependWith)

Prepend the key names of an associative array.

static array
only(array $array, array|string $keys)

Get a subset of the items from the given array.

static array
onlyValues(array $array, mixed $values, bool $strict = false)

Get a subset of the items from the given array by value.

static array
select(array $array, array|string $keys)

Select an array of values from an array.

static array
pluck(iterable $array, string|array|int|Closure|null $value, string|array|Closure|null $key = null)

Pluck an array of values from an array.

static array
explodePluckParameters(Closure|array|string $value, string|array|Closure|null $key)

Explode the "value" and "key" arguments passed to "pluck".

static array
map(array $array, callable $callback)

Run a map over each of the items in the array.

static array
mapWithKeys(array $array, callable $callback)

Run an associative map over each of the items.

static TValue>
mapSpread(array $array, callable $callback)

Run a map over each nested chunk of items.

static array
prepend(array $array, mixed $value, mixed $key = null)

Push an item onto the beginning of an array.

static mixed
pull(array $array, string|int $key, mixed $default = null)

Get a value from the array, and remove it.

static string
query(array $array)

Convert the array into a query string.

static ($number is null ? mixed : array)
random(array $array, int|null $number = null, bool $preserveKeys = false)

Get one or a specified number of random values from an array.

static array
set(array $array, string|int|null $key, mixed $value)

Set an array item to a given value using "dot" notation.

static array
push(ArrayAccess|array $array, string|int|null $key, mixed ...$values)

Push an item into an array using "dot" notation.

static array
shuffle(array $array)

Shuffle the given array and return the result.

static 
sole(array $array, callable|null $callback = null)

Get the first item in the array, but only if exactly one item exists. Otherwise, throw an exception.

static TValue>
sort(TValue> $array, callable|string|null|TValue): -1|0|1)|SortDirection|"asc"|"desc"}> $callback = null)

Sort the array using the given callback or "dot" notation.

static TValue>
sortDesc(TValue> $array, callable|string|null|TValue): -1|0|1)|array{string, "asc"|"desc"}> $callback = null)

Sort the array in descending order using the given callback or "dot" notation.

static TValue>
sortRecursive(TValue> $array, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE> $options = SORT_REGULAR, SortDirection|bool $descending = false)

Recursively sort an array by keys and values.

static TValue>
sortRecursiveDesc(TValue> $array, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE> $options = SORT_REGULAR)

Recursively sort an array by keys and values in descending order.

static string
string(ArrayAccess|array $array, string|int|null $key, string|null $default = null)

Get a string item from an array using "dot" notation.

static ($array is array<string, false> ? "" : ($array is "" ? "" : ($array is array{} ? "" : non-empty-string)))
toCssClasses(array<string, bool>|array<int, string|int>|string $array)

Conditionally compile classes from an array into a CSS class list.

static ($array is array<string, false> ? "" : ($array is "" ? "" : ($array is array{} ? "" : non-empty-string)))
toCssStyles(array<string, bool>|array<int, string|int>|string $array)

Conditionally compile styles from an array into a style list.

static TValue>
where(TValue> $array, callable $callback)

Filter the array using the given callback.

static TValue>
reject(TValue> $array, callable $callback)

Filter the array using the negation of the given callback.

static TValue>>
partition(TValue> $array, callable $callback)

Partition the array into two arrays using the given callback.

static TValue>
whereNotNull(TValue|null> $array)

Filter items where the value is not null.

static TValue}))
wrap(TValue>|TValue|null $value)

If the given value is not an array and not null, wrap it in one.

Details

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

static bool accessible(mixed $value)

Determine whether the given value is array accessible.

Parameters

mixed $value

Return Value

bool

static JsonSerializable ? true : false))))) arrayable(mixed $value)

Determine whether the given value is arrayable.

Parameters

mixed $value

Return Value

JsonSerializable ? true : false)))))

static array add(array $array, string|int|float $key, mixed $value)

Add an element to an array using "dot" notation if it doesn't exist.

Parameters

array $array
string|int|float $key
mixed $value

Return Value

array

static array array(ArrayAccess|array $array, string|int|null $key, array|null $default = null)

Get an array item from an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|int|null $key
array|null $default

Return Value

array

Exceptions

InvalidArgumentException

static bool boolean(ArrayAccess|array $array, string|int|null $key, bool|null $default = null)

Get a boolean item from an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|int|null $key
bool|null $default

Return Value

bool

Exceptions

InvalidArgumentException

static array collapse(iterable $array)

Collapse an array of arrays into a single array.

Parameters

iterable $array

Return Value

array

static TValue>> crossJoin(TValue> ...$arrays)

Cross join the given arrays, returning all possible permutations.

Parameters

TValue> ...$arrays

Return Value

TValue>>

static TValue[]} divide(TValue> $array)

Divide an array into two arrays. One with keys and the other with values.

Parameters

TValue> $array

Return Value

TValue[]}

static array dot(iterable $array, string $prepend = '', int $depth = INF)

Flatten a multi-dimensional associative array with dots.

Parameters

iterable $array
string $prepend
int $depth

Return Value

array

static array undot(iterable $array)

Convert a flatten "dot" notation array into an expanded array.

Parameters

iterable $array

Return Value

array

static array except(array $array, array|string|int|float $keys)

Get all of the given array except for a specified array of keys.

Parameters

array $array
array|string|int|float $keys

Return Value

array

static array exceptValues(array $array, mixed $values, bool $strict = false)

Get all of the given array except for a specified array of values.

Parameters

array $array
mixed $values
bool $strict

Return Value

array

static bool exists(ArrayAccess|array $array, string|int|float $key)

Determine if the given key exists in the provided array.

Parameters

ArrayAccess|array $array
string|int|float $key

Return Value

bool

static TValue|TFirstDefault first(TValue> $array, callable|null $callback = null, TFirstDefault|TFirstDefault $default = null)

Return the first element in an iterable passing a given truth test.

Parameters

TValue> $array
callable|null $callback
TFirstDefault|TFirstDefault $default

Return Value

TValue|TFirstDefault

static TValue|TLastDefault last(TValue> $array, callable|null $callback = null, TLastDefault|TLastDefault $default = null)

Return the last element in an array passing a given truth test.

Parameters

TValue> $array
callable|null $callback
TLastDefault|TLastDefault $default

Return Value

TValue|TLastDefault

static array take(array $array, int $limit)

Take the first or last {$limit} items from an array.

Parameters

array $array
int $limit

Return Value

array

static array flatten(iterable $array, int $depth = INF)

Flatten a multi-dimensional array into a single level.

Parameters

iterable $array
int $depth

Return Value

array

static float float(ArrayAccess|array $array, string|int|null $key, float|null $default = null)

Get a float item from an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|int|null $key
float|null $default

Return Value

float

Exceptions

InvalidArgumentException

static void forget(array $array, array|string|int|float $keys)

Remove one or many array items from a given array using "dot" notation.

Parameters

array $array
array|string|int|float $keys

Return Value

void

static TValue>) from(TValue>|TValue>|TValue>|TValue>|TValue>|Jsonable|JsonSerializable|object $items)

Get the underlying array of items from the given argument.

Parameters

TValue>|TValue>|TValue>|TValue>|TValue>|Jsonable|JsonSerializable|object $items

Return Value

TValue>)

Exceptions

InvalidArgumentException

static mixed get(ArrayAccess|array $array, string|int|null $key, mixed $default = null)

Get an item from an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|int|null $key
mixed $default

Return Value

mixed

static bool has(ArrayAccess|array $array, string|array $keys)

Check if an item or items exist in an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|array $keys

Return Value

bool

static bool hasAll(ArrayAccess|array $array, string|array $keys)

Determine if all keys exist in an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|array $keys

Return Value

bool

static bool hasAny(ArrayAccess|array $array, string|array $keys)

Determine if any of the keys exist in an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|array $keys

Return Value

bool

static bool every(iterable $array, callable $callback)

Determine if all items pass the given truth test.

Parameters

iterable $array
callable $callback

Return Value

bool

static bool some(iterable $array, callable $callback)

Determine if some items pass the given truth test.

Parameters

iterable $array
callable $callback

Return Value

bool

static int integer(ArrayAccess|array $array, string|int|null $key, int|null $default = null)

Get an integer item from an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|int|null $key
int|null $default

Return Value

int

Exceptions

InvalidArgumentException

static ($array is list ? false : true) isAssoc(array $array)

Determines if an array is associative.

An array is "associative" if it doesn't have sequential numerical keys beginning with zero.

Parameters

array $array

Return Value

($array is list ? false : true)

static ($array is list ? true : false) isList(array $array)

Determines if an array is a list.

An array is a "list" if all array keys are sequential integers starting from 0 with no gaps in between.

Parameters

array $array

Return Value

($array is list ? true : false)

static string join(array $array, string $glue, string $finalGlue = '')

Join all items using a string. The final items can use a separate glue string.

Parameters

array $array
string $glue
string $finalGlue

Return Value

string

static array keyBy(iterable $array, callable|array|string $keyBy)

Key an associative array by a field or using a callback.

Parameters

iterable $array
callable|array|string $keyBy

Return Value

array

static array prependKeysWith(array $array, string $prependWith)

Prepend the key names of an associative array.

Parameters

array $array
string $prependWith

Return Value

array

static array only(array $array, array|string $keys)

Get a subset of the items from the given array.

Parameters

array $array
array|string $keys

Return Value

array

static array onlyValues(array $array, mixed $values, bool $strict = false)

Get a subset of the items from the given array by value.

Parameters

array $array
mixed $values
bool $strict

Return Value

array

static array select(array $array, array|string $keys)

Select an array of values from an array.

Parameters

array $array
array|string $keys

Return Value

array

static array pluck(iterable $array, string|array|int|Closure|null $value, string|array|Closure|null $key = null)

Pluck an array of values from an array.

Parameters

iterable $array
string|array|int|Closure|null $value
string|array|Closure|null $key

Return Value

array

static protected array explodePluckParameters(Closure|array|string $value, string|array|Closure|null $key)

Explode the "value" and "key" arguments passed to "pluck".

Parameters

Closure|array|string $value
string|array|Closure|null $key

Return Value

array

static array map(array $array, callable $callback)

Run a map over each of the items in the array.

Parameters

array $array
callable $callback

Return Value

array

static array mapWithKeys(array $array, callable $callback)

Run an associative map over each of the items.

The callback should return an associative array with a single key/value pair.

Parameters

array $array
callable $callback

Return Value

array

static TValue> mapSpread(array $array, callable $callback)

Run a map over each nested chunk of items.

Parameters

array $array
callable $callback

Return Value

TValue>

static array prepend(array $array, mixed $value, mixed $key = null)

Push an item onto the beginning of an array.

Parameters

array $array
mixed $value
mixed $key

Return Value

array

static mixed pull(array $array, string|int $key, mixed $default = null)

Get a value from the array, and remove it.

Parameters

array $array
string|int $key
mixed $default

Return Value

mixed

static string query(array $array)

Convert the array into a query string.

Parameters

array $array

Return Value

string

static ($number is null ? mixed : array) random(array $array, int|null $number = null, bool $preserveKeys = false)

Get one or a specified number of random values from an array.

Parameters

array $array
int|null $number
bool $preserveKeys

Return Value

($number is null ? mixed : array)

Exceptions

InvalidArgumentException

static array set(array $array, string|int|null $key, mixed $value)

Set an array item to a given value using "dot" notation.

If no key is given to the method, the entire array will be replaced.

Parameters

array $array
string|int|null $key
mixed $value

Return Value

array

static array push(ArrayAccess|array $array, string|int|null $key, mixed ...$values)

Push an item into an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|int|null $key
mixed ...$values

Return Value

array

static array shuffle(array $array)

Shuffle the given array and return the result.

Parameters

array $array

Return Value

array

static sole(array $array, callable|null $callback = null)

Get the first item in the array, but only if exactly one item exists. Otherwise, throw an exception.

Parameters

array $array
callable|null $callback

Exceptions

ItemNotFoundException
MultipleItemsFoundException

static TValue> sort(TValue> $array, callable|string|null|TValue): -1|0|1)|SortDirection|"asc"|"desc"}> $callback = null)

Sort the array using the given callback or "dot" notation.

Parameters

TValue> $array
callable|string|null|TValue): -1|0|1)|SortDirection|"asc"|"desc"}> $callback

Return Value

TValue>

static TValue> sortDesc(TValue> $array, callable|string|null|TValue): -1|0|1)|array{string, "asc"|"desc"}> $callback = null)

Sort the array in descending order using the given callback or "dot" notation.

Parameters

TValue> $array
callable|string|null|TValue): -1|0|1)|array{string, "asc"|"desc"}> $callback

Return Value

TValue>

static TValue> sortRecursive(TValue> $array, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE> $options = SORT_REGULAR, SortDirection|bool $descending = false)

Recursively sort an array by keys and values.

Parameters

TValue> $array
SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE> $options
SortDirection|bool $descending

Return Value

TValue>

static TValue> sortRecursiveDesc(TValue> $array, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE> $options = SORT_REGULAR)

Recursively sort an array by keys and values in descending order.

Parameters

TValue> $array
SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE> $options

Return Value

TValue>

static string string(ArrayAccess|array $array, string|int|null $key, string|null $default = null)

Get a string item from an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|int|null $key
string|null $default

Return Value

string

Exceptions

InvalidArgumentException

static ($array is array<string, false> ? "" : ($array is "" ? "" : ($array is array{} ? "" : non-empty-string))) toCssClasses(array<string, bool>|array<int, string|int>|string $array)

Conditionally compile classes from an array into a CSS class list.

Parameters

array<string, bool>|array<int, string|int>|string $array

Return Value

($array is array<string, false> ? "" : ($array is "" ? "" : ($array is array{} ? "" : non-empty-string)))

static ($array is array<string, false> ? "" : ($array is "" ? "" : ($array is array{} ? "" : non-empty-string))) toCssStyles(array<string, bool>|array<int, string|int>|string $array)

Conditionally compile styles from an array into a style list.

Parameters

array<string, bool>|array<int, string|int>|string $array

Return Value

($array is array<string, false> ? "" : ($array is "" ? "" : ($array is array{} ? "" : non-empty-string)))

static TValue> where(TValue> $array, callable $callback)

Filter the array using the given callback.

Parameters

TValue> $array
callable $callback

Return Value

TValue>

static TValue> reject(TValue> $array, callable $callback)

Filter the array using the negation of the given callback.

Parameters

TValue> $array
callable $callback

Return Value

TValue>

static TValue>> partition(TValue> $array, callable $callback)

Partition the array into two arrays using the given callback.

Parameters

TValue> $array
callable $callback

Return Value

TValue>>

static TValue> whereNotNull(TValue|null> $array)

Filter items where the value is not null.

Parameters

TValue|null> $array

Return Value

TValue>

static TValue})) wrap(TValue>|TValue|null $value)

If the given value is not an array and not null, wrap it in one.

Parameters

TValue>|TValue|null $value

Return Value

TValue}))

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.