-
-
Notifications
You must be signed in to change notification settings - Fork 28
Closed
Labels
Description
Would this be useful? A 4th option for ArrayHelper::index which specifies the key should be removed from the array.
Helps avoid some duplication of data. I can do PR and tests if it's likely to be used.
$array = [
['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
['id' => '345', 'data' => 'def', 'device' => 'tablet'],
['id' => '345', 'data' => 'hgi', 'device' => 'smartphone'],
];$result = ArrayHelper::index($array, 'id');
[
'123' => ['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
'345' => ['id' => '345', 'data' => 'hgi', 'device' => 'smartphone']
]$result = ArrayHelper::index($array, 'id', [], true);
[
'123' => ['data' => 'abc', 'device' => 'laptop'],
'345' => ['data' => 'hgi', 'device' => 'smartphone']
]