Arr

class Arr (View source)

Traits

Macroable

Properties

static protected array $macros The registered string macros. from Macroable

Methods

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

Register a custom macro.

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

Mix another object into the class.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

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

Dynamically handle calls to the class.

from Macroable
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
static bool accessible(mixed $value)

Determine whether the given value is array accessible.

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

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

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

Determine if the given key exists in the provided array.

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

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

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

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

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

Flatten a multi-dimensional array into a single level.

static void forget(array $array, array|string $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 array only(array $array, array|string $keys)

Get a subset of the items from the given array.

static array pluck(iterable $array, string|array $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 prepend(array $array, mixed $value, mixed $key = null)

Push an item onto the beginning of an array.

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

Get a value from the array, and remove it.

static mixed random(array $array, int|null $number = null)

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

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

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

static array shuffle(array $array, int|null $seed = null)

Shuffle the given array and return the result.

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

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

static array sortRecursive(array $array)

Recursively sort an array by keys and values.

static string query(array $array)

Convert the array into a query string.

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

Filter the array using the given callback.

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 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 $key, mixed $value)

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

Parameters

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

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

Parameters

array $array
array|string $keys

Return Value

array

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

Determine if the given key exists in the provided array.

Parameters

ArrayAccess|array $array
string|int $key

Return Value

bool

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

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

Parameters

iterable $array
callable $callback
mixed $default

Return Value

mixed

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

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

Parameters

array $array
callable $callback
mixed $default

Return Value

mixed

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 $keys)

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

Parameters

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

Pluck an array of values from an array.

Parameters

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

Get a value from the array, and remove it.

Parameters

array $array
string $key
mixed $default

Return Value

mixed

static mixed random(array $array, int|null $number = null)

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

Parameters

array $array
int|null $number

Return Value

mixed

Exceptions

InvalidArgumentException

static array set(array $array, string|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|null $key
mixed $value

Return Value

array

static array shuffle(array $array, int|null $seed = null)

Shuffle the given array and return the result.

Parameters

array $array
int|null $seed

Return Value

array

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

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

Parameters

array $array
callable|string|null $callback

Return Value

array

static array sortRecursive(array $array)

Recursively sort an array by keys and values.

Parameters

array $array

Return Value

array

static string query(array $array)

Convert the array into a query string.

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 wrap(mixed $value)

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

Parameters

mixed $value

Return Value

array

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/7.x/Illuminate/Support/Arr.html