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'];
});
~~~