PHP 클래스 Yiinitializr\Helpers\ArrayX

부터: 1.0
저자: Antonio Ramirez ([email protected])
파일 보기 프로젝트 열기: 2amigos/yiinitializr 1 사용 예제들

공개 메소드들

메소드 설명
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