Arr

class Arr (View source)

Traits

MacroableTrait

Properties

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

Methods

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

Register a custom macro.

from MacroableTrait
static boolean hasMacro(string $name)

Checks if macro is registered

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

Dynamically handle calls to the class.

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

Dynamically handle calls to the class.

from MacroableTrait
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 build(array $array, Closure $callback)

Build a new array using a callback.

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 array fetch(array $array, string $key)

Fetch a flattened array of a nested array element.

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

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

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

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

static array flatten(array $array)

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

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

static bool has(array $array, string $key)

Check if an item exists in an array using "dot" notation.

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

Get a subset of the items from the given array.

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

Pluck an array of values from 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 sort(array $array, Closure $callback)

Sort the array using the given Closure.

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

Filter the array using the given Closure.

Details

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

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

static boolean hasMacro(string $name)

Checks if macro is registered

Parameters

string $name

Return Value

boolean

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 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 build(array $array, Closure $callback)

Build a new array using a callback.

Parameters

array $array
Closure $callback

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 array fetch(array $array, string $key)

Fetch a flattened array of a nested array element.

Parameters

array $array
string $key

Return Value

array

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

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

Parameters

array $array
Closure $callback
mixed $default

Return Value

mixed

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

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

Parameters

array $array
Closure $callback
mixed $default

Return Value

mixed

static array flatten(array $array)

Flatten a multi-dimensional array into a single level.

Parameters

array $array

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

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

Parameters

array $array
string $key
mixed $default

Return Value

mixed

static bool has(array $array, string $key)

Check if an item exists in an array using "dot" notation.

Parameters

array $array
string $key

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

Pluck an array of values from an array.

Parameters

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

Sort the array using the given Closure.

Parameters

array $array
Closure $callback

Return Value

array

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

Filter the array using the given Closure.

Parameters

array $array
Closure $callback

Return Value

array

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