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 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
collapse(iterable $array)

Collapse an array of arrays into a single array.

static array
crossJoin(iterable ...$arrays)

Cross join the given arrays, returning all possible permutations.

static array
divide(array $array)

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

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

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 bool
exists(ArrayAccess|array $array, string|int|float $key)

Determine if the given key exists in the provided array.

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

No description

static mixed
last(array $array, callable|null $callback = null, mixed $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 void
forget(array $array, array|string|int|float $keys)

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

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
hasAny(ArrayAccess|array $array, string|array $keys)

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

static bool
isAssoc(array $array)

Determines if an array is associative.

static bool
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(array $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
select(array $array, array|string $keys)

Select an array of values from an array.

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

Pluck an array of values from an array.

static array
explodePluckParameters(string|array $value, string|array|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 
mapWithKeys(array $array, callable $callback)

No description

static 
mapSpread(array $array, callable $callback)

No description

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 mixed
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
shuffle(array $array)

Shuffle the given array and return the result.

static array
sort(array $array, callable|array|string|null $callback = null)

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

static array
sortDesc(array $array, callable|array|string|null $callback = null)

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

static array
sortRecursive(array $array, int $options = SORT_REGULAR, bool $descending = false)

Recursively sort an array by keys and values.

static array
sortRecursiveDesc(array $array, int $options = SORT_REGULAR)

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

static string
toCssClasses(array $array)

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

static string
toCssStyles(array $array)

Conditionally compile styles from an array into a style list.

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

Filter the array using the given callback.

static array
whereNotNull(array $array)

Filter items where the value is not null.

static array
wrap(mixed $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 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 collapse(iterable $array)

Collapse an array of arrays into a single array.

Parameters

iterable $array

Return Value

array

static array crossJoin(iterable ...$arrays)

Cross join the given arrays, returning all possible permutations.

Parameters

iterable ...$arrays

Return Value

array

static array divide(array $array)

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

Parameters

array $array

Return Value

array

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

Flatten a multi-dimensional associative array with dots.

Parameters

iterable $array
string $prepend

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 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 first($array, callable|null $callback = null, $default = null)

No description

Parameters

$array
callable|null $callback
$default

static mixed last(array $array, callable|null $callback = null, mixed $default = null)

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

Parameters

array $array
callable|null $callback
mixed $default

Return Value

mixed

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 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 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 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 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

bool

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.

Parameters

array $array

Return Value

bool

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(array $array, callable|array|string $keyBy)

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

Parameters

array $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 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|null $value, string|array|null $key = null)

Pluck an array of values from an array.

Parameters

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

Return Value

array

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

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

Parameters

string|array $value
string|array|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 mapWithKeys(array $array, callable $callback)

No description

Parameters

array $array
callable $callback

static mapSpread(array $array, callable $callback)

No description

Parameters

array $array
callable $callback

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 mixed 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

mixed

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 shuffle(array $array)

Shuffle the given array and return the result.

Parameters

array $array

Return Value

array

static array sort(array $array, callable|array|string|null $callback = null)

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

Parameters

array $array
callable|array|string|null $callback

Return Value

array

static array sortDesc(array $array, callable|array|string|null $callback = null)

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

Parameters

array $array
callable|array|string|null $callback

Return Value

array

static array sortRecursive(array $array, int $options = SORT_REGULAR, bool $descending = false)

Recursively sort an array by keys and values.

Parameters

array $array
int $options
bool $descending

Return Value

array

static array sortRecursiveDesc(array $array, int $options = SORT_REGULAR)

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

Parameters

array $array
int $options

Return Value

array

static string toCssClasses(array $array)

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

Parameters

array $array

Return Value

string

static string toCssStyles(array $array)

Conditionally compile styles from an array into a style list.

Parameters

array $array

Return Value

string

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

Filter the array using the given callback.

Parameters

array $array
callable $callback

Return Value

array

static array whereNotNull(array $array)

Filter items where the value is not null.

Parameters

array $array

Return Value

array

static array wrap(mixed $value)

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

Parameters

mixed $value

Return Value

array