Arr
class Arr
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Determine whether the given value is array accessible.
Determine whether the given value is arrayable.
Add an element to an array using "dot" notation if it doesn't exist.
Get an array item from an array using "dot" notation.
Get a boolean item from an array using "dot" notation.
Collapse an array of arrays into a single array.
Cross join the given arrays, returning all possible permutations.
Divide an array into two arrays. One with keys and the other with values.
Flatten a multi-dimensional associative array with dots.
Convert a flatten "dot" notation array into an expanded array.
Get all of the given array except for a specified array of keys.
Get all of the given array except for a specified array of values.
Determine if the given key exists in the provided array.
Return the first element in an iterable passing a given truth test.
Return the last element in an iterable passing a given truth test.
Take the first or last {$limit} items from an array.
Flatten a multi-dimensional array into a single level.
Get a float item from an array using "dot" notation.
Remove one or many array items from a given array using "dot" notation.
Get the underlying array of items from the given argument.
Get an item from an array using "dot" notation.
Check if an item or items exist in an array using "dot" notation.
Determine if all keys exist in an array using "dot" notation.
Determine if any of the keys exist in an array using "dot" notation.
Determine if all items pass the given truth test.
Determine if some items pass the given truth test.
Get an integer item from an array using "dot" notation.
Determines if an array is associative.
Determines if an array is a list.
Join all items using a string. The final items can use a separate glue string.
Key an associative array by a field or using a callback.
Prepend the key names of an associative array.
Get a subset of the items from the given array.
Get a subset of the items from the given array by value.
Select an array of values from an array.
Explode the "value" and "key" arguments passed to "pluck".
Run a map over each of the items in the array.
Run an associative map over each of the items.
Run a map over each nested chunk of items.
Push an item onto the beginning of an array.
Get a value from the array, and remove it.
Convert the array into a query string.
Get one or a specified number of random values from an array.
Set an array item to a given value using "dot" notation.
Push an item into an array using "dot" notation.
Shuffle the given array and return the result.
Get the first item in the array, but only if exactly one item exists. Otherwise, throw an exception.
Sort the array using the given callback or "dot" notation.
Sort the array in descending order using the given callback or "dot" notation.
Recursively sort an array by keys and values.
Recursively sort an array by keys and values in descending order.
Get a string item from an array using "dot" notation.
Conditionally compile classes from an array into a CSS class list.
Conditionally compile styles from an array into a style list.
Filter the array using the given callback.
Filter the array using the negation of the given callback.
Partition the array into two arrays using the given callback.
Filter items where the value is not null.
If the given value is not an array and not null, wrap it in one.
Flush all static state.
Details
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 27
static bool
accessible(mixed $value)
Determine whether the given value is array accessible.
at line 37
static bool
arrayable(mixed $value)
Determine whether the given value is arrayable.
at line 49
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.
at line 63
static array
array(ArrayAccess|array $array, string|int|null $key, array|null $default = null)
Get an array item from an array using "dot" notation.
at line 81
static bool
boolean(ArrayAccess|array $array, string|int|null $key, bool|null $default = null)
Get a boolean item from an array using "dot" notation.
at line 97
static array
collapse(iterable $array)
Collapse an array of arrays into a single array.
at line 120
static array
crossJoin(iterable ...$arrays)
Cross join the given arrays, returning all possible permutations.
at line 150
static array
divide(array $array)
Divide an array into two arrays. One with keys and the other with values.
at line 158
static array
dot(iterable $array, string $prepend = '', int|float $depth = INF)
Flatten a multi-dimensional associative array with dots.
at line 185
static array
undot(iterable $array)
Convert a flatten "dot" notation array into an expanded array.
at line 199
static array
except(array $array, array|string|int|float|null $keys)
Get all of the given array except for a specified array of keys.
at line 209
static array
exceptValues(array $array, mixed $values, bool $strict = false)
Get all of the given array except for a specified array of values.
at line 221
static bool
exists(ArrayAccess|array $array, string|int|float|null $key)
Determine if the given key exists in the provided array.
at line 250
static mixed
first(iterable $array, callable|null $callback = null, mixed $default = null)
Return the first element in an iterable passing a given truth test.
at line 295
static mixed
last(iterable|null $array, callable|null $callback = null, mixed $default = null)
Return the last element in an iterable passing a given truth test.
at line 342
static array
take(array $array, int $limit)
Take the first or last {$limit} items from an array.
at line 354
static array
flatten(iterable $array, float $depth = INF)
Flatten a multi-dimensional array into a single level.
at line 382
static float
float(ArrayAccess|array $array, string|int|null $key, float|null $default = null)
Get a float item from an array using "dot" notation.
at line 398
static void
forget(array $array, array|string|int|float|null $keys)
Remove one or many array items from a given array using "dot" notation.
at line 446
static array
from(mixed $items)
Get the underlying array of items from the given argument.
at line 465
static mixed
get(mixed $array, string|int|float|null $key, mixed $default = null)
Get an item from an array using "dot" notation.
at line 497
static bool
has(mixed $array, array|string|int|float|null $keys)
Check if an item or items exist in an array using "dot" notation.
at line 527
static bool
hasAll(mixed $array, array|string|int|float|null $keys)
Determine if all keys exist in an array using "dot" notation.
at line 548
static bool
hasAny(mixed $array, array|string|int|float|null $keys)
Determine if any of the keys exist in an array using "dot" notation.
at line 577
static bool
every(iterable $array, callable $callback)
Determine if all items pass the given truth test.
at line 595
static bool
some(iterable $array, callable $callback)
Determine if some items pass the given truth test.
at line 615
static int
integer(ArrayAccess|array $array, string|int|null $key, int|null $default = null)
Get an integer item from an array using "dot" notation.
at line 635
static bool
isAssoc(array $array)
Determines if an array is associative.
An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
at line 647
static bool
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.
at line 655
static string
join(array $array, string $glue, string $finalGlue = '')
Join all items using a string. The final items can use a separate glue string.
at line 677
static array
keyBy(iterable $array, callable|array|string $keyBy)
Key an associative array by a field or using a callback.
at line 690
static array
prependKeysWith(array $array, string $prependWith)
Prepend the key names of an associative array.
at line 698
static array
only(array $array, array|string|int|float|null $keys)
Get a subset of the items from the given array.
at line 706
static array
onlyValues(array $array, mixed $values, bool $strict = false)
Get a subset of the items from the given array by value.
at line 718
static array
select(array $array, array|string|int|float|null $keys)
Select an array of values from an array.
at line 740
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.
at line 779
static protected array
explodePluckParameters(array|Closure|string $value, null|array|Closure|string $key)
Explode the "value" and "key" arguments passed to "pluck".
at line 791
static array
map(array $array, callable $callback)
Run a map over each of the items in the array.
at line 817
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.
at line 840
static array
mapSpread(array $array, callable $callback)
Run a map over each nested chunk of items.
at line 852
static array
prepend(array $array, mixed $value, mixed $key = null)
Push an item onto the beginning of an array.
at line 866
static mixed
pull(array $array, string|int $key, mixed $default = null)
Get a value from the array, and remove it.
at line 878
static string
query(array $array)
Convert the array into a query string.
at line 890
static mixed
random(array $array, int|string|null $number = null, bool $preserveKeys = false)
Get one or a specified number of random values from an array.
at line 940
static array
set(array $array, string|int|float|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.
at line 975
static array
push(array $array, string|int|null $key, mixed ...$values)
Push an item into an array using "dot" notation.
ArrayAccess cannot support the nested by-reference mutation required by dot notation.
at line 987
static array
shuffle(array $array)
Shuffle the given array and return the result.
at line 998
static mixed
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.
at line 1027
static array
sort(iterable $array, callable|array|int|string|null $callback = null)
Sort the array using the given callback or "dot" notation.
at line 1048
static array
sortDesc(iterable $array, callable|array|int|string|null $callback = null)
Sort the array in descending order using the given callback or "dot" notation.
at line 1069
static array
sortRecursive(array $array, int $options = SORT_REGULAR, SortDirection|bool $descending = false)
Recursively sort an array by keys and values.
at line 1102
static array
sortRecursiveDesc(array $array, int $options = SORT_REGULAR)
Recursively sort an array by keys and values in descending order.
at line 1112
static string
string(ArrayAccess|array $array, string|int|null $key, string|null $default = null)
Get a string item from an array using "dot" notation.
at line 1130
static string
toCssClasses(array|string $array)
Conditionally compile classes from an array into a CSS class list.
at line 1152
static string
toCssStyles(array|string $array)
Conditionally compile styles from an array into a style list.
at line 1179
static array
where(array $array, callable $callback)
Filter the array using the given callback.
at line 1194
static array
reject(array $array, callable $callback)
Filter the array using the negation of the given callback.
at line 1209
static array
partition(iterable $array, callable $callback)
Partition the array into two arrays using the given callback.
at line 1234
static array
whereNotNull(array $array)
Filter items where the value is not null.
at line 1248
static array
wrap(mixed $value)
If the given value is not an array and not null, wrap it in one.
at line 1260
static void
flushState()
Flush all static state.