Collection
Table of Contents
Methods
- clone() : array<string|int, mixed>
- Clone array recursively. Keys are preserved
- firstNotEmpty() : mixed|string
- Takes all arguments by pairs.. Odd arguments are arrays.
- getByNestedKey() : mixed
- Returns $array[p1][p2][p3] with $key = [p1, p2, p3]
- isAssociative() : bool
- Check array is associative.
- normalizeArrayValuesByInt() : void
- Convert array values to int, return unique values > 0. Optionally sorted array.
- setByNestedKey() : void
- Sets value $array[p1][p2][p3] = $value with $key = [p1, p2, p3]
- sortByColumn() : mixed
- Sorting array by column.
- unsetByNestedKey() : void
- Unsets last key in array $array[p1][p2][p3] with $key = [p1, p2, p3]
Methods
clone()
Clone array recursively. Keys are preserved
public
static clone(array<string|int, mixed> $originalArray) : array<string|int, mixed>
Parameters
- $originalArray : array<string|int, mixed>
-
- array to clone
Return values
array<string|int, mixed>firstNotEmpty()
Takes all arguments by pairs.. Odd arguments are arrays.
public
static firstNotEmpty() : mixed|string
Even arguments are keys to lookup in these arrays. Keys may be arrays. In this case function will try to dig deeper. Returns first not empty element of a[k] pair.
Return values
mixed|stringgetByNestedKey()
Returns $array[p1][p2][p3] with $key = [p1, p2, p3]
public
static getByNestedKey(array<string|int, mixed> $array, array<string|int, mixed> $key) : mixed
Parameters
- $array : array<string|int, mixed>
- $key : array<string|int, mixed>
isAssociative()
Check array is associative.
public
static isAssociative(mixed $array) : bool
Parameters
- $array : mixed
-
- Array for check.
Return values
boolnormalizeArrayValuesByInt()
Convert array values to int, return unique values > 0. Optionally sorted array.
public
static normalizeArrayValuesByInt(array<string|int, mixed> &$map[, bool $sorted = true ]) : void
Parameters
- $map : array<string|int, mixed>
-
Array for normalize.
- $sorted : bool = true
-
If sorted true, result array will be sorted.
setByNestedKey()
Sets value $array[p1][p2][p3] = $value with $key = [p1, p2, p3]
public
static setByNestedKey(array<string|int, mixed> &$array, array<string|int, mixed> $key, mixed $value) : void
Parameters
- $array : array<string|int, mixed>
- $key : array<string|int, mixed>
- $value : mixed
Tags
sortByColumn()
Sorting array by column.
public
static sortByColumn(array<string|int, mixed> &$array, string|array<string|int, mixed> $columns[, string|array<string|int, mixed> $callbacks = '' ][, null $defaultValueIfNotSetValue = null ][, bool $preserveKeys = false ]) : mixed
You can use short mode: Collection::sortByColumn($arr, 'value'); This is equal Collection::sortByColumn($arr, array('value' => SORT_ASC))
Pay attention: if two members compare as equal, their relative order in the sorted array is undefined. The sorting is not stable.
More example: Collection::sortByColumn($arr, array('value' => array(SORT_NUMERIC, SORT_ASC), 'attr' => SORT_DESC), array('attr' => 'strlen'), 'www');
Parameters
- $array : array<string|int, mixed>
- $columns : string|array<string|int, mixed>
- $callbacks : string|array<string|int, mixed> = ''
- $defaultValueIfNotSetValue : null = null
-
If value not set - use $defaultValueIfNotSetValue (any cols)
- $preserveKeys : bool = false
-
If false numeric keys will be re-indexed. If true - preserve.
Tags
unsetByNestedKey()
Unsets last key in array $array[p1][p2][p3] with $key = [p1, p2, p3]
public
static unsetByNestedKey(array<string|int, mixed> &$array, array<string|int, mixed> $key) : void
Parameters
- $array : array<string|int, mixed>
- $key : array<string|int, mixed>