The truth is php DOES offer a single, native function that allows you to replace the outer indexes with the values of a single column. The "magic" is in the 2nd parameter which tells php not to touch the subarray values when assigning the new keys.
Code: (Demo)
$indexed = [
['id' => 'john', 'name' => 'John', 'age' => 29],
['id' => 'peter', 'name' => 'Peter', 'age' => 30],
['id' => 'harry', 'name' => 'Harry', 'age' => 19],
];
var_export(array_column($indexed, null, 'id'));
Output:
array (
'john' =>
array (
'id' => 'john',
'name' => 'John',
'age' => 29,
),
'peter' =>
array (
'id' => 'peter',
'name' => 'Peter',
'age' => 30,
),
'harry' =>
array (
'id' => 'harry',
'name' => 'Harry',
'age' => 19,
),
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…