CodeIgniter v4.5 API

array_helper.php

This file is part of 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

Functions

dot_array_search()  : array<string|int, mixed>|bool|int|object|string|null
Searches an array through dot syntax. Supports wildcard searches, like foo.*.bar
array_deep_search()  : array<string|int, mixed>|bool|float|int|object|string|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.
array_group_by()  : array<string|int, mixed>
Groups all rows by their index values. Result's depth equals number of indexes

Functions

Searches an array through dot syntax. Supports wildcard searches, like foo.*.bar

dot_array_search(string $index, array<string|int, mixed> $array) : array<string|int, mixed>|bool|int|object|string|null
Parameters
$index : string
$array : array<string|int, mixed>
Return values
array<string|int, mixed>|bool|int|object|string|null

Returns the value of an element at a key in an array of uncertain depth.

array_deep_search(int|string $key, array<string|int, mixed> $array) : array<string|int, mixed>|bool|float|int|object|string|null
Parameters
$key : int|string
$array : array<string|int, mixed>
Return values
array<string|int, mixed>|bool|float|int|object|string|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(iterable<string|int, mixed> $array[, string $id = '' ]) : array<string|int, mixed>
Parameters
$array : iterable<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

array_group_by()

Groups all rows by their index values. Result's depth equals number of indexes

array_group_by(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

Return values
array<string|int, mixed>

Result array where rows are grouped together by indexes values.


        
On this page

Search results