PHP Класс Yiinitializr\Helpers\ArrayX

С версии: 1.0
Автор: Antonio Ramirez ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Описание методов

deepMap() публичный статический Метод

Credits to Util.php
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

deepSearch() публичный статический Метод

Credits to Util.php
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

divide() публичный статический Метод

Divide an array into two arrays. One with keys and the other with values.
public static divide ( array $array ) : array
$array array
Результат array

except() публичный статический Метод

Get all of the given array except for a specified array of items.
public static except ( array $array, array $keys ) : array
$array array
$keys array
Результат array

first() публичный статический Метод

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');
public static first ( array $array, Closure $callback, mixed $default = null ) : mixed
$array array
$callback Closure
$default mixed
Результат mixed

forget() публичный статический Метод

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');
public static forget ( array &$array, string $key ) : void
$array array
$key string
Результат void

get() публичный статический Метод

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');
public static get ( array | CAttributeCollection $array, string $key, mixed $default = null ) : mixed
$array array | CAttributeCollection
$key string
$default mixed
Результат mixed

head() публичный статический Метод

This is simply a convenient wrapper around the "reset" method.
public static head ( array $array ) : mixed
$array array
Результат mixed

merge() публичный статический Метод

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.
public static merge ( array $a, array $b ) : array
$a array array to be merged to
$b array array to be merged from. You can specifiy additional arrays via third argument, fourth argument etc.
Результат array the merged array (the original arrays are not changed.)

only() публичный статический Метод

Get a subset of the items from the given array.
public static only ( array $array, array $keys ) : array
$array array
$keys array
Результат array

pluck() публичный статический Метод

Pluck an array of values from an array.
public static pluck ( array $array, string $key ) : array
$array array
$key string
Результат array

pop() публичный статический Метод

If no key is found, then default value will be returned.
public static pop ( &$array, $key, null $default = null ) : mixed | null
$array
$key
$default null
Результат mixed | null

set() публичный статический Метод

If no key is given to the method, the entire array will be replaced. 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 set ( array &$array, string $key, mixed $value ) : void
$array array
$key string
$value mixed
Результат void

stripSlashes() публичный статический Метод

Recursively remove slashes from array keys and values.
public static stripSlashes ( array $array ) : array
$array array
Результат array

value() публичный статический Метод

If the given item is a Closure the result of the Closure will be returned.
public static value ( mixed $value ) : mixed
$value mixed
Результат mixed