메소드 | 설명 | |
---|---|---|
filter ( array $array, array $filters ) : array | Filters array according to rules specified. | |
getColumn ( array $array, string | Closure $name, boolean $keepKeys = true ) : array | Returns the values of a specified column in an array. | |
getValue ( array | object $array, string | Closure | array $key, mixed $default = null ) : mixed | Retrieves the value of an array element or object property with the given key or property name. | |
htmlDecode ( array $data, boolean $valuesOnly = true ) : array | Decodes HTML entities into the corresponding characters in an array of strings. | |
htmlEncode ( array $data, boolean $valuesOnly = true, string $charset = null ) : array | Encodes special characters in an array of strings into HTML entities. | |
index ( array $array, string | Closure | null $key, string | string[] | Closure[] | null $groups = [] ) : array | Indexes and/or groups the array according to a specified key. | |
isAssociative ( array $array, boolean $allStrings = true ) : boolean | Returns a value indicating whether the given array is an associative array. | |
isIn ( mixed $needle, array | Traversable $haystack, boolean $strict = false ) : boolean | Check whether an array or [[\Traversable]] contains an element. | |
isIndexed ( array $array, boolean $consecutive = false ) : boolean | Returns a value indicating whether the given array is an indexed array. | |
isSubset ( array | Traversable $needles, array | Traversable $haystack, boolean $strict = false ) : boolean | Checks whether an array or [[\Traversable]] is a subset of another array or [[\Traversable]]. | |
isTraversable ( mixed $var ) : boolean | Checks whether a variable is an array or [[\Traversable]]. | |
keyExists ( string $key, array $array, boolean $caseSensitive = true ) : boolean | Checks if the given array contains the specified key. | |
map ( array $array, string | Closure $from, string | Closure $to, string | Closure $group = null ) : array | Builds a map (key-value pairs) from a multidimensional array or an array of objects. | |
merge ( array $a, array $b ) : array | Merges two or more arrays into one recursively. | |
multisort ( array &$array, string | Closure | array $key, integer | array $direction = SORT_ASC, integer | array $sortFlag = SORT_REGULAR ) | Sorts an array of objects or arrays (with the same structure) by one or several keys. | |
remove ( array &$array, string $key, mixed $default = null ) : mixed | null | Removes an item from an array and returns the value. If the key does not exist in the array, the default value will be returned instead. | |
removeValue ( array &$array, string $value ) : array | Removes items with matching values from the array and returns the removed items. | |
toArray ( object | array | string $object, array $properties = [], boolean $recursive = true ) : array | Converts an object or an array of objects into an array. |
public static filter ( array $array, array $filters ) : array | ||
$array | array | Source array |
$filters | array | Rules that define array keys which should be left or removed from results. Each rule is: - `var` - `$array['var']` will be left in result. - `var.key` = only `$array['var']['key'] will be left in result. - `!var.key` = `$array['var']['key'] will be removed from result. |
리턴 | array | Filtered array |
public static getValue ( array | object $array, string | Closure | array $key, mixed $default = null ) : mixed | ||
$array | array | object | array or object to extract value from |
$key | string | Closure | array | key name of the array element, an array of keys or property name of the object, or an anonymous function returning the value. The anonymous function signature should be: `function($array, $defaultValue)`. The possibility to pass an array of keys is available since version 2.0.4. |
$default | mixed | the default value to be returned if the specified array key does not exist. Not used when getting value from an object. |
리턴 | mixed | the value of the element if found, default value otherwise |
public static htmlEncode ( array $data, boolean $valuesOnly = true, string $charset = null ) : array | ||
$data | array | data to be encoded |
$valuesOnly | boolean | whether to encode array values only. If false, both the array keys and array values will be encoded. |
$charset | string | the charset that the data is using. If not set, [[\yii\base\Application::charset]] will be used. |
리턴 | array | the encoded data |
public static index ( array $array, string | Closure | null $key, string | string[] | Closure[] | null $groups = [] ) : array | ||
$array | array | the array that needs to be indexed or grouped |
$key | string | Closure | null | the column name or anonymous function which result will be used to index the array |
$groups | string | string[] | Closure[] | null | the array of keys, that will be used to group the input array by one or more keys. If the $key attribute or its value for the particular element is null and $groups is not defined, the array element will be discarded. Otherwise, if $groups is specified, array element will be added to the result array without any key. This parameter is available since version 2.0.8. |
리턴 | array | the indexed and/or grouped array |
public static isIn ( mixed $needle, array | Traversable $haystack, boolean $strict = false ) : boolean | ||
$needle | mixed | The value to look for. |
$haystack | array | Traversable | The set of values to search. |
$strict | boolean | Whether to enable strict (`===`) comparison. |
리턴 | boolean | `true` if `$needle` was found in `$haystack`, `false` otherwise. |
public static isSubset ( array | Traversable $needles, array | Traversable $haystack, boolean $strict = false ) : boolean | ||
$needles | array | Traversable | The values that must **all** be in `$haystack`. |
$haystack | array | Traversable | The set of value to search. |
$strict | boolean | Whether to enable strict (`===`) comparison. |
리턴 | boolean | `true` if `$needles` is a subset of `$haystack`, `false` otherwise. |
public static isTraversable ( mixed $var ) : boolean | ||
$var | mixed | The variable being evaluated. |
리턴 | boolean | whether $var is array-like |
public static multisort ( array &$array, string | Closure | array $key, integer | array $direction = SORT_ASC, integer | array $sortFlag = SORT_REGULAR ) | ||
$array | array | the array to be sorted. The array will be modified after calling this method. |
$key | string | Closure | array | the key(s) to be sorted by. This refers to a key name of the sub-array elements, a property name of the objects, or an anonymous function returning the values for comparison purpose. The anonymous function signature should be: `function($item)`. To sort by multiple keys, provide an array of keys here. |
$direction | integer | array | the sorting direction. It can be either `SORT_ASC` or `SORT_DESC`. When sorting by multiple keys with different sorting directions, use an array of sorting directions. |
$sortFlag | integer | array | the PHP sort flag. Valid values include `SORT_REGULAR`, `SORT_NUMERIC`, `SORT_STRING`, `SORT_LOCALE_STRING`, `SORT_NATURAL` and `SORT_FLAG_CASE`. Please refer to [PHP manual](http://php.net/manual/en/function.sort.php) for more details. When sorting by multiple keys with different sort flags, use an array of sort flags. |
public static remove ( array &$array, string $key, mixed $default = null ) : mixed | null | ||
$array | array | the array to extract value from |
$key | string | key name of the array element |
$default | mixed | the default value to be returned if the specified key does not exist |
리턴 | mixed | null | the value of the element if found, default value otherwise |
public static toArray ( object | array | string $object, array $properties = [], boolean $recursive = true ) : array | ||
$object | object | array | string | the object to be converted into an array |
$properties | array | a mapping from object class names to the properties that need to put into the resulting arrays. The properties specified for each class is an array of the following format: ```php [ 'app\models\Post' => [ 'id', 'title', // the key name in array result => property name 'createTime' => 'created_at', // the key name in array result => anonymous function 'length' => function ($post) { return strlen($post->content); }, ], ] ``` The result of `ArrayHelper::toArray($post, $properties)` could be like the following: ```php [ 'id' => 123, 'title' => 'test', 'createTime' => '2013-01-01 12:00AM', 'length' => 301, ] ``` |
$recursive | boolean | whether to recursively converts properties which are objects into arrays. |
리턴 | array | the array representation of the object |