Skip to content

FR: ArrayHelper::index, remove key from array #5

@alex-code

Description

@alex-code

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']
]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions