Methods summary
public static
mixed
|
#
dotGet( array $array, string $key, null|mixed $default = null )
Get the resulting value of an attempt to traverse a key path.
Get the resulting value of an attempt to traverse a key path.
Each key in the path is separated with a dot.
For example, the following snippet should return true :
Arr::dotGet([ 'hello' => [ 'world' => true, ],
], 'hello.world');
Additionally, a default value may be provided, which will be returned if
the path does not yield to a value.
Parameters
Returns
mixed
|
public static
|
#
dotSet( array $array, string $key, mixed $value )
Set an array element using dot notation.
Set an array element using dot notation.
Same as Arr::dotGet() , but the value is replaced instead of fetched.
Parameters
Throws
|
public static
array
|
#
walkCopy( array $array, callable $callback, boolean $recurse = false, string $path = '', boolean $considerLeaves = true )
Like walk() but it uses a copy of the array instead.
Like walk() but it uses a copy of the array instead.
Parameters
- $array
- $callback
- $recurse
- $path
- $considerLeaves
Returns
array
|
public static
array
|
#
walk( array & $array, callable $callback, boolean $recurse = false, string $path = '', boolean $considerLeaves = true )
A more complicated, but flexible, version of array_walk .
A more complicated, but flexible, version of array_walk .
This modified version is useful for flattening arrays without losing
important structure data (how the array is arranged and nested).
Possible applications: flattening complex validation responses or a
configuration file.
Additional features:
- The current path in dot notation is provided to the callback.
- Leaf arrays (no nested arrays) can be optionally ignored.
Callback signature:
$callback($key, $value, $array, $path);
Parameters
- $array
- $callback
- $recurse
- $path
- $considerLeaves
Returns
array
|
public static
boolean
|
#
hasNested( array $array )
Return whether or not an array has nested arrays.
Return whether or not an array has nested arrays.
Parameters
Returns
boolean
|
public static
boolean
|
#
has( array $input, string|integer $key )
Return whether or not an array contains the specified key.
Return whether or not an array contains the specified key.
Parameters
Returns
boolean
|
public static
array
|
#
filterNullValues( array $properties, array $allowed = null )
Get array elements that are not null.
Get array elements that are not null.
Parameters
Returns
array
|
public static
array
|
#
only( array $input, array|null $included = [] )
Get an array with only the specified keys of the provided array.
Get an array with only the specified keys of the provided array.
Parameters
Returns
array
|
public static
array
|
#
filterKeys( array $input, array $included = [] )
Filter the keys of an array to only the allowed set.
Filter the keys of an array to only the allowed set.
Deprecated
Parameters
Returns
array
Throws
|
public static
array
|
#
except( array $input, array $excluded = [] )
Get a copy of the provided array excluding the specified keys.
Get a copy of the provided array excluding the specified keys.
Parameters
Returns
array
Throws
|
public static
array
|
#
exceptValues( array $input, array $excluded = [] )
Get a copy of the provided array excluding the specified values.
Get a copy of the provided array excluding the specified values.
Parameters
Returns
array
Throws
|
public static
|
#
exchange( array & $elements, integer $indexA, integer $indexB )
Exchange two elements in an array.
Exchange two elements in an array.
Parameters
- $elements
- $indexA
- $indexB
Throws
|
public static
array|mixed
|
#
mergev( array $arrayv )
Merge a vector of arrays performantly. Borrowed from libphutil.
This has the same semantics as array_merge(), so these calls are
equivalent:.
Merge a vector of arrays performantly. Borrowed from libphutil.
This has the same semantics as array_merge(), so these calls are
equivalent:.
array_merge($a, $b, $c); array_mergev(array($a, $b, $c));
However, when you have a vector of arrays, it is vastly more performant
to merge them with this function than by calling array_merge() in a loop,
because using a loop generates an intermediary array on each iteration.
Parameters
Returns
array|mixed
Throws
|
public static
array<string|int>
|
#
keys( array $input )
Get each key in an array.
Get each key in an array.
Parameters
Returns
array<string|int>
|
public static
array
|
#
values( array $input )
Get the value of each element in the array.
Get the value of each element in the array.
Parameters
Returns
array
|
public static
mixed
|
#
head( array $input )
Extract the first element in an array.
Extract the first element in an array.
Parameters
Returns
mixed
Throws
|
public static
array
|
#
tail( array $input )
Extract the last element of an array.
Extract the last element of an array.
Parameters
Returns
array
Throws
|
public static
mixed
|
#
last( array $input )
Extract the last element in an array.
Extract the last element in an array.
Parameters
Returns
mixed
Throws
|
public static
array
|
#
init( array $input )
Extract all the elements of an array except the last one.
Extract all the elements of an array except the last one.
Parameters
Returns
array
Throws
|
public static
array
|
#
reverse( array $input )
Return the provided array with all its elements in the inverse order.
Return the provided array with all its elements in the inverse order.
Parameters
Returns
array
|
public static
array
|
#
drop( array $input, integer $count )
Returns the suffix of element after the first N elements.
Returns the suffix of element after the first N elements.
Parameters
Returns
array
|
public static
integer|string|boolean
|
#
indexOf( array $input, mixed $value )
Returns the index of the first occurrence of a value in the provided
array.
Returns the index of the first occurrence of a value in the provided
array.
If the value is not found, false is returned.
Parameters
Returns
integer|string|boolean
|
public static
array
|
#
take( array $input, integer $count )
Returns the suffix of elements before the first N elements
Returns the suffix of elements before the first N elements
Parameters
Returns
array
|
public static
array
|
#
merge( array $base, array $extension )
Merge two arrays together.
Merge two arrays together.
Parameters
Returns
array
|
public static
boolean
|
#
in( array $input, mixed $value )
Check if an array contains the provided value.
Check if an array contains the provided value.
Parameters
Returns
boolean
|