PHP Класс VersionPress\Utils\ArrayUtils

Показать файл Открыть проект Примеры использования класса

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

Метод Описание
all ( array $array, callable $predicate ) : boolean Determines whether all elements of an array satisfy a condition.
any ( array $array, callable $predicate ) : boolean Determines whether any element of an array satisfies a condition.
isAssociative ( mixed $array ) : boolean Returns true if the array is associative. Associative being defined as an array containing at least one string key.
map ( callable $mapFn, array $array ) : array Extends array_map function with keys.
mapreduce ( $data, $mapFn, $reduceFn ) : array Transforms and groups data in array $mapFn emits key and value. These values are grouped by their keys and passed into $reduceFn which can transform the group and emit result.
parametrize ( $array )
stablesort ( &$array, string $cmp_function = 'strcmp' ) Similar to usort() but maintains order of equal items (the algorithm is "stable").
unique ( array $array, callable | null $fn = null ) : array Removes duplicate values from an array.

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

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

Determines whether all elements of an array satisfy a condition.
public static all ( array $array, callable $predicate ) : boolean
$array array
$predicate callable
Результат boolean

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

Determines whether any element of an array satisfies a condition.
public static any ( array $array, callable $predicate ) : boolean
$array array
$predicate callable
Результат boolean

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

Returns true if the array is associative. Associative being defined as an array containing at least one string key.
public static isAssociative ( mixed $array ) : boolean
$array mixed Array is generally expected but any value may be provided (will return false)
Результат boolean

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

The $mapFn takes two params - $value and $key.
public static map ( callable $mapFn, array $array ) : array
$mapFn callable
$array array
Результат array

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

$mapFn has signature ($item, $mapEmit) where $item is item from data and $mapEmit is emit function $reduceFn has signature ($key, $items, $reduceEmit) where $key is the key the data are grouped by, $items is the group and $reduce emit is an emit function $mapEmit has signature ($key, $value) where $key is the key the data are grouped by and $value is a transformed item $reduceEmit has signature ($obj) where $obj is the transformed group
public static mapreduce ( $data, $mapFn, $reduceFn ) : array
$data
$mapFn
$reduceFn
Результат array

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

public static parametrize ( $array )

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

Adapted from http://stackoverflow.com/a/4353844/21728 / http://php.net/manual/en/function.usort.php#38827
public static stablesort ( &$array, string $cmp_function = 'strcmp' )
$array
$cmp_function string

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

Uses custom function to map the values to a comparable value. It preserves keys.
public static unique ( array $array, callable | null $fn = null ) : array
$array array
$fn callable | null
Результат array