\think\helperArr

Summary

Methods
Properties
Constants
accessible()
add()
collapse()
crossJoin()
divide()
dot()
except()
exists()
first()
last()
flatten()
forget()
get()
has()
isAssoc()
only()
pluck()
prepend()
pull()
random()
set()
shuffle()
sort()
sortRecursive()
query()
where()
wrap()
No public properties found
No constants found
explodePluckParameters()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

accessible()

accessible(mixed  $value) : bool

Determine whether the given value is array accessible.

Parameters

mixed $value

Returns

bool —

add()

add(array  $array, string  $key, mixed  $value) : array

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

Parameters

array $array
string $key
mixed $value

Returns

array —

collapse()

collapse(array  $array) : array

Collapse an array of arrays into a single array.

Parameters

array $array

Returns

array —

crossJoin()

crossJoin(array  ...$arrays) : array

Cross join the given arrays, returning all possible permutations.

Parameters

array $arrays variadic

Returns

array —

divide()

divide(array  $array) : array

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

Parameters

array $array

Returns

array —

dot()

dot(array  $array, string  $prepend = '') : array

Flatten a multi-dimensional associative array with dots.

Parameters

array $array
string $prepend

Returns

array —

except()

except(array  $array, array|string  $keys) : array

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

Parameters

array $array
array|string $keys

Returns

array —

exists()

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

Determine if the given key exists in the provided array.

Parameters

\ArrayAccess|array $array
string|int $key

Returns

bool —

first()

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

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

Parameters

array $array
callable|null $callback
mixed $default

Returns

mixed —

last()

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

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

Parameters

array $array
callable|null $callback
mixed $default

Returns

mixed —

flatten()

flatten(array  $array, int  $depth = INF) : array

Flatten a multi-dimensional array into a single level.

Parameters

array $array
int $depth

Returns

array —

forget()

forget(array  $array, array|string  $keys) : void

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

Parameters

array $array
array|string $keys

get()

get(\ArrayAccess|array  $array, string  $key, mixed  $default = null) : mixed

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

Parameters

\ArrayAccess|array $array
string $key
mixed $default

Returns

mixed —

has()

has(\ArrayAccess|array  $array, string|array  $keys) : bool

Check if an item or items exist in an array using "dot" notation.

Parameters

\ArrayAccess|array $array
string|array $keys

Returns

bool —

isAssoc()

isAssoc(array  $array) : bool

Determines if an array is associative.

An array is "associative" if it doesn't have sequential numerical keys beginning with zero.

Parameters

array $array

Returns

bool —

only()

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

Get a subset of the items from the given array.

Parameters

array $array
array|string $keys

Returns

array —

pluck()

pluck(array  $array, string|array  $value, string|array|null  $key = null) : array

Pluck an array of values from an array.

Parameters

array $array
string|array $value
string|array|null $key

Returns

array —

prepend()

prepend(array  $array, mixed  $value, mixed  $key = null) : array

Push an item onto the beginning of an array.

Parameters

array $array
mixed $value
mixed $key

Returns

array —

pull()

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

Get a value from the array, and remove it.

Parameters

array $array
string $key
mixed $default

Returns

mixed —

random()

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

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

Parameters

array $array
int|null $number

Throws

\InvalidArgumentException

Returns

mixed —

set()

set(array  $array, string  $key, mixed  $value) : array

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

Returns

array —

shuffle()

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

Shuffle the given array and return the result.

Parameters

array $array
int|null $seed

Returns

array —

sort()

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

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

Parameters

array $array
callable|string|null $callback

Returns

array —

sortRecursive()

sortRecursive(array  $array) : array

Recursively sort an array by keys and values.

Parameters

array $array

Returns

array —

query()

query(array  $array) : string

Convert the array into a query string.

Parameters

array $array

Returns

string —

where()

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

Filter the array using the given callback.

Parameters

array $array
callable $callback

Returns

array —

wrap()

wrap(mixed  $value) : array

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

Parameters

mixed $value

Returns

array —

explodePluckParameters()

explodePluckParameters(string|array  $value, string|array|null  $key) : array

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

Parameters

string|array $value
string|array|null $key

Returns

array —