array_helper.php
This file is part of the CodeIgniter 4 framework.
(c) CodeIgniter Foundation admin@codeigniter.com
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
Table of Contents
- dot_array_search() : mixed
- Searches an array through dot syntax. Supports wildcard searches, like foo.*.bar
- array_deep_search() : mixed|null
- Returns the value of an element at a key in an array of uncertain depth.
- array_sort_by_multiple_keys() : bool
- Sorts a multidimensional array by its elements values. The array columns to be used for sorting are passed as an associative array of key names and sorting flags.
- array_flatten_with_dots() : array<string|int, mixed>
- Flatten a multidimensional array using dots as separators.
Functions
dot_array_search()
Searches an array through dot syntax. Supports wildcard searches, like foo.*.bar
dot_array_search(string $index, array<string|int, mixed> $array) : mixed
Parameters
- $index : string
- $array : array<string|int, mixed>
Return values
mixed —array_deep_search()
Returns the value of an element at a key in an array of uncertain depth.
array_deep_search(mixed $key, array<string|int, mixed> $array) : mixed|null
Parameters
- $key : mixed
- $array : array<string|int, mixed>
Return values
mixed|null —array_sort_by_multiple_keys()
Sorts a multidimensional array by its elements values. The array columns to be used for sorting are passed as an associative array of key names and sorting flags.
array_sort_by_multiple_keys(array<string|int, mixed> &$array, array<string|int, mixed> $sortColumns) : bool
Both arrays of objects and arrays of array can be sorted.
Example: array_sort_by_multiple_keys($players, [ 'team.hierarchy' => SORT_ASC, 'position' => SORT_ASC, 'name' => SORT_STRING, ]);
The '.' dot operator in the column name indicates a deeper array or object level. In principle, any number of sublevels could be used, as long as the level and column exist in every array element.
For information on multi-level array sorting, refer to Example #3 here: https://www.php.net/manual/de/function.array-multisort.php
Parameters
- $array : array<string|int, mixed>
-
the reference of the array to be sorted
- $sortColumns : array<string|int, mixed>
-
an associative array of columns to sort after and their sorting flags
Return values
bool —array_flatten_with_dots()
Flatten a multidimensional array using dots as separators.
array_flatten_with_dots(iteratable<string|int, mixed> $array[, string $id = '' ]) : array<string|int, mixed>
Parameters
- $array : iteratable<string|int, mixed>
-
The multi-dimensional array
- $id : string = ''
-
Something to initially prepend to the flattened keys
Return values
array<string|int, mixed> —The flattened array