ArrayHelper
in package
Tags
Table of Contents
Methods
- dotKeyExists() : bool
- array_key_exists() with dot array syntax.
- dotSearch() : array<string|int, mixed>|bool|int|object|string|null
- Searches an array through dot syntax. Supports wildcard searches, like `foo.*.bar`.
- groupBy() : array<string|int, mixed>
- Groups all rows by their index values. Result's depth equals number of indexes
- recursiveCount() : int
- Recursively count all keys.
- recursiveDiff() : array<string|int, mixed>
- Compare recursively two associative arrays and return difference as new array.
- sortValuesByNatural() : bool
- Sorts array values in natural order If the value is an array, you need to specify the $sortByIndex of the key to sort
- arrayAttachIndexedValue() : array<string|int, mixed>
- Recursively attach $row to the $indexes path of values found by `dot_array_search()`.
- arraySearchDot() : array<string|int, mixed>|bool|float|int|object|string|null
- Recursively search the array with wildcards.
- convertToArray() : array<int, string>
Methods
dotKeyExists()
array_key_exists() with dot array syntax.
public
static dotKeyExists(string $index, array<string|int, mixed> $array) : bool
If wildcard *
is used, all items for the key after it must have the key.
Parameters
- $index : string
- $array : array<string|int, mixed>
Return values
booldotSearch()
Searches an array through dot syntax. Supports wildcard searches, like `foo.*.bar`.
public
static dotSearch(string $index, array<string|int, mixed> $array) : array<string|int, mixed>|bool|int|object|string|null
Parameters
- $index : string
-
The index as dot array syntax.
- $array : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>|bool|int|object|string|nullgroupBy()
Groups all rows by their index values. Result's depth equals number of indexes
public
static groupBy(array<string|int, mixed> $array, array<string|int, mixed> $indexes[, bool $includeEmpty = false ]) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
-
Data array (i.e. from query result)
- $indexes : array<string|int, mixed>
-
Indexes to group by. Dot syntax used. Returns $array if empty
- $includeEmpty : bool = false
-
If true, null and '' are also added as valid keys to group
Tags
Return values
array<string|int, mixed> —Result array where rows are grouped together by indexes values.
recursiveCount()
Recursively count all keys.
public
static recursiveCount(array<string|int, mixed> $array[, int $counter = 0 ]) : int
Parameters
- $array : array<string|int, mixed>
- $counter : int = 0
Return values
intrecursiveDiff()
Compare recursively two associative arrays and return difference as new array.
public
static recursiveDiff(array<string|int, mixed> $original, array<string|int, mixed> $compareWith) : array<string|int, mixed>
Returns keys that exist in $original
but not in $compareWith
.
Parameters
- $original : array<string|int, mixed>
- $compareWith : array<string|int, mixed>
Return values
array<string|int, mixed>sortValuesByNatural()
Sorts array values in natural order If the value is an array, you need to specify the $sortByIndex of the key to sort
public
static sortValuesByNatural(array<int, int|array<int, int|string>|string> &$array[, int|string|null $sortByIndex = null ]) : bool
Parameters
- $array : array<int, int|array<int, int|string>|string>
- $sortByIndex : int|string|null = null
Return values
boolarrayAttachIndexedValue()
Recursively attach $row to the $indexes path of values found by `dot_array_search()`.
private
static arrayAttachIndexedValue(array<string|int, mixed> $result, array<string|int, mixed> $row, array<string|int, mixed> $indexes, bool $includeEmpty) : array<string|int, mixed>
Parameters
- $result : array<string|int, mixed>
- $row : array<string|int, mixed>
- $indexes : array<string|int, mixed>
- $includeEmpty : bool
Tags
Return values
array<string|int, mixed>arraySearchDot()
Recursively search the array with wildcards.
private
static arraySearchDot(array<string|int, mixed> $indexes, array<string|int, mixed> $array) : array<string|int, mixed>|bool|float|int|object|string|null
Parameters
- $indexes : array<string|int, mixed>
- $array : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>|bool|float|int|object|string|nullconvertToArray()
private
static convertToArray(string $index) : array<int, string>
Parameters
- $index : string
-
The index as dot array syntax.
Return values
array<int, string> —The index as an array.