Do you know a smarter way to use an array entry value as key?
Consider this array:
$array = [
0 => [
'id' => 1,
'title' => 'Title 1',
],
2 => [
'id' => 2,
'title' => 'Title 1',
],
3 => [
'id' => 3,
'title' => 'Title 1',
]
];
To replace each array key with value of id
I do this:
$new_array = [];
foreach ($array AS $item) {
$new_array[$item['id']] = $item;
}
unset($array);
$array = array_column($array, null, 'id');
Look at the description of the column_key
and index_key
arguments: http://php.net/array_column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With