PHP Класс infoweb\cms\helpers\ArrayHelper

С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\helpers\BaseArrayHelper
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
indexRecursive ( array $array, string | Closure $key ) : array Indexes an array according to a specified key.

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

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

The input array should be multidimensional or an array of objects. The key can be a key name of the sub-array, a property name of object, or an anonymous function which returns the key value given an array element. If a key value is null, the corresponding array element will be discarded and not put in the result. For example, ~~~ $array = [ ['id' => '123', 'data' => 'abc'], ['id' => '345', 'data' => 'def'], ]; $result = ArrayHelper::index($array, 'id'); the result is: [ '123' => ['id' => '123', 'data' => 'abc'], '345' => ['id' => '345', 'data' => 'def'], ] using anonymous function $result = ArrayHelper::index($array, function ($element) { return $element['id']; }); ~~~
public static indexRecursive ( array $array, string | Closure $key ) : array
$array array the array that needs to be indexed
$key string | Closure the column name or anonymous function whose result will be used to index the array
Результат array the indexed array