class Arr (View source)

A collection of tools dealing with arrays

Methods

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

Collapse an array of arrays into a single array.

static array
divide(array $array)

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

static array
dot(array $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 items.

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

Determine if the given key exists in the provided array.

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

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

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

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

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

Pluck an array of values from an array.

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 array
set(array $array, string $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
sortRecursive(array $array)

Recursively sort an array by keys and values.

static mixed
data_get(mixed $target, string|array $key, mixed $default = null)

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

Details

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

Collapse an array of arrays into a single array.

Parameters

array $array

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(array $array, string $prepend = '')

Flatten a multi-dimensional associative array with dots.

Parameters

array $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 items.

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

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

Parameters

array $array
callable|null $callback
mixed $default

Return Value

mixed

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

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

Parameters

array $array
callable|null $callback
mixed $default

Return Value

mixed

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

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

Parameters

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

Pluck an array of values from an array.

Parameters

array $array
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 array set(array $array, string $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 $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 sortRecursive(array $array)

Recursively sort an array by keys and values.

Parameters

array $array

Return Value

array

static mixed data_get(mixed $target, string|array $key, mixed $default = null)

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

Parameters

mixed $target
string|array $key
mixed $default

Return Value

mixed