public static
array
|
#
copy( array $names, array $from, array $to )
Copies the values from one option array to another.
Copies the values from one option array to another.
Parameters
- $names
array $names the items names to copy.
- $from
array $from the items to copy from.
- $to
array $to the items to copy to.
Returns
array with copied items.
|
public static
array
|
#
move( array $names, array $from, array $to )
Moves the item values from one array to another.
Moves the item values from one array to another.
Parameters
- $names
array $names the item names to move.
- $from
array $from the values to move from.
- $to
array $to the items to move to.
Returns
array with moved items.
|
public static
array
|
#
multipleDefaultValues( array $array, array $defaults )
Sets multiple default values for the given array.
Sets multiple default values for the given array.
Parameters
- $array
array $array the items to set defaults for.
- $defaults
array $defaults the default items.
Returns
array the array with default values.
|
public static
mixed
|
#
defaultValue( string $name, mixed $value, array $array )
Sets the default value for an item in the given array.
Sets the default value for an item in the given array.
Parameters
- $name
string $name the name of the item.
- $value
mixed $value the default value.
- $array
array $array the items.
Returns
mixed
|
public static
array
|
#
addValue( string $key, string $value, array & $array, string $glue = ' ' )
Adds a new option to the given array. If the key does not exists, it will
create one, if it exists it will append the value and also makes sure the
uniqueness of them.
Adds a new option to the given array. If the key does not exists, it will
create one, if it exists it will append the value and also makes sure the
uniqueness of them.
Parameters
- $key
string $key the key name at the array
- $value
string $value the value to add / append
- $array
array $array the options to modify
- $glue
string $glue how the values will be joined
Returns
array
|
public static
mixed
|
#
getValue( array|object $array, string|Closure $key, mixed $default = null )
Retrieves the value of an array element or object property with the given key
or property name. If the key does not exist in the array, the default value will
be returned instead.
Retrieves the value of an array element or object property with the given key
or property name. If the key does not exist in the array, the default value will
be returned instead.
Parameters
- $array
array|object $array array or object to extract value from
- $key
string|Closure $key key name of the array element, or property name of the object, or an
anonymous function returning the value. The anonymous function signature should
be: function($array, $defaultValue) .
- $default
mixed $default the default value to be returned if the specified key does not exist
Returns
mixed the value of the
|
public static
mixed|null
|
#
removeValue( mixed & $array, mixed $key, null $default = null )
Removes an item from the given options and returns the value.
Removes an item from the given options and returns the value.
If no key is found, then default value will be returned.
Parameters
- $array
mixed $array
- $key
mixed $key
- $default
null $default
Returns
mixed|null
|
public static
array
|
#
removeKeys( array $array, array $names )
Removes the array values from the given array.
Removes the array values from the given array.
Parameters
- $array
array $array the items to remove from.
- $names
array $names names to remove from the array.
Returns
array the items.
|
public static
array
|
#
divide( array $array )
Divide an array into two arrays. One with keys and the other with values.
Divide an array into two arrays. One with keys and the other with values.
Parameters
Returns
array
|
public static
array
|
#
pluck( array $array, string $key )
Pluck an array of values from an array.
Pluck an array of values from an array.
Parameters
- $array
array $array
- $key
string $key
Returns
array
|
public static
array
|
#
only( array $array, array $keys )
Get a subset of the items from the given array.
Get a subset of the items from the given array.
Parameters
- $array
array $array
- $keys
array $keys
Returns
array
|
public static
array
|
#
except( array $array, array $keys )
Get all of the given array except for a specified array of items.
Get all of the given array except for a specified array of items.
Parameters
- $array
array $array
- $keys
array $keys
Returns
array
|
public static
mixed
|
#
first( array $array, Closure $callback, mixed $default = null )
Return the first element in an array which passes a given truth test.
Return the first element in an array which passes a given truth test.
$value = ArrayX::first($array, function($k, $v) {return $v == 'Taylor';});
$value = ArrayX::first($array, function($k, $v) {return $v == 'Taylor'}, 'Default');
Parameters
- $array
array $array
- $callback
Closure
$callback
- $default
mixed $default
Returns
mixed
|
public static
mixed
|
#
head( array $array )
Return the first element of an array.
Return the first element of an array.
This is simply a convenient wrapper around the "reset" method.
Parameters
Returns
mixed
|
public static
array
|
#
merge( array $a, array $b )
Merges two or more arrays into one recursively. If each array has an element
with the same string key value, the latter will overwrite the former (different
from array_merge_recursive). Recursive merging will be conducted if both arrays
have an element of array type and are having the same key. For integer-keyed
elements, the elements from the latter array will be appended to the former
array.
Merges two or more arrays into one recursively. If each array has an element
with the same string key value, the latter will overwrite the former (different
from array_merge_recursive). Recursive merging will be conducted if both arrays
have an element of array type and are having the same key. For integer-keyed
elements, the elements from the latter array will be appended to the former
array.
Parameters
- $a
array $a array to be merged to
- $b
array $b array to be merged from. You can specifiy additional arrays via third
argument, fourth argument etc.
Returns
array the merged array (the original arrays are not changed.)
|
public static
boolean|mixed|string
|
#
search( array $array, string $search, boolean $field = false )
Searches for a given value in an array of arrays, objects and scalar values.
You can optionally specify a field of the nested arrays and objects to search
in.
Searches for a given value in an array of arrays, objects and scalar values.
You can optionally specify a field of the nested arrays and objects to search
in.
Credits to Util.php
Parameters
- $array
array $array The array to search
- $search
string $search The value to search for
- $field
boolean $field The field to search in, if not specified all fields will be searched
Returns
boolean|mixed|string false on failure or the array key on
Link
|
public static
array
|
#
map( array $array, mixed $callback, boolean $on_nonscalar = false )
Returns an array containing all the elements of arr1 after applying the
callback function to each one.
Returns an array containing all the elements of arr1 after applying the
callback function to each one.
Credits to Util.php
Parameters
- $array
array $array an array to run through the callback function
- $callback
mixed $callback Callback function to run for each element in each array
- $on_nonscalar
boolean $on_nonscalar whether or not to call the callback function on nonscalar values
(objects, resr, etc)
Returns
array
Link
|
protected static
mixed
|
#
value( mixed $value )
Return the value of the given item.
Return the value of the given item.
If the given item is a Closure the result of the Closure will be
returned.
Parameters
Returns
mixed
|