메소드 | 설명 | |
---|---|---|
deepMap ( array $array, $callback, boolean $on_nonscalar = FALSE ) : array | Returns an array containing all the elements of arr1 after applying the callback function to each one. | |
deepSearch ( array $array, string $search, boolean $field = FALSE ) : boolean | mixed | string | 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. | |
divide ( array $array ) : array | Divide an array into two arrays. One with keys and the other with values. | |
except ( array $array, array $keys ) : array | Get all of the given array except for a specified array of items. | |
first ( array $array, Closure $callback, mixed $default = null ) : mixed | Return the first element in an array which passes a given truth test. | |
forget ( array &$array, string $key ) : void | Remove an array item from a given array using "dot" notation. | |
get ( array | CAttributeCollection $array, string $key, mixed $default = null ) : mixed | Get an item from an array using "dot" notation. | |
head ( array $array ) : mixed | Return the first element of an array. | |
merge ( array $a, array $b ) : array | Merges two or more arrays into one recursively. | |
only ( array $array, array $keys ) : array | Get a subset of the items from the given array. | |
pluck ( array $array, string $key ) : array | Pluck an array of values from an array. | |
pop ( &$array, $key, null $default = null ) : mixed | null | Removes an item from the given options and returns the value. | |
set ( array &$array, string $key, mixed $value ) : void | Set an array item to a given value using "dot" notation. | |
stripSlashes ( array $array ) : array | Recursively remove slashes from array keys and values. | |
value ( mixed $value ) : mixed | Return the value of the given item. |
public static deepMap ( array $array, $callback, boolean $on_nonscalar = FALSE ) : array | ||
$array | array | an array to run through the callback function |
$callback | Callback function to run for each element in each array | |
$on_nonscalar | boolean | whether or not to call the callback function on nonscalar values (objects, resr, etc) |
리턴 | array |
public static deepSearch ( array $array, string $search, boolean $field = FALSE ) : boolean | mixed | string | ||
$array | array | The array to search |
$search | string | The value to search for |
$field | boolean | The field to search in, if not specified all fields will be searched |
리턴 | boolean | mixed | string | False on failure or the array key on |
Return the first array element that equals "Taylor"
$value = ArrayX::first($array, function($k, $v) {return $v == 'Taylor';});
Return a default value if no matching element is found
$value = ArrayX::first($array, function($k, $v) {return $v == 'Taylor'}, 'Default');
Remove the $array['user']['name'] item from the array
ArrayX::forget($array, 'user.name');
Remove the $array['user']['name']['first'] item from the array
ArrayX::forget($array, 'user.name.first');
Get the $array['user']['name'] value from the array
$name = ArrayX::get($array, 'user.name');
Return a default from if the specified item doesn't exist
$name = ArrayX::get($array, 'user.name', 'Taylor');
Set the $array['user']['name'] value on the array
ArrayX::set($array, 'user.name', 'Taylor');
Set the $array['user']['name']['first'] value on the array
ArrayX::set($array, 'user.name.first', 'Michael');
public static stripSlashes ( array $array ) : array | ||
$array | array | |
리턴 | array |