Let's assume I have an array of elements, which are arrays themselves, like so:
$array = [
['foo' => 'ABC', 'bar' => 'DEF'],
['foo' => 'ABB', 'bar' => 'DDD'],
['foo' => 'BAC', 'bar' => 'EFF'],
];
To set the values of the foo
field as the key of the array I could do this:
foreach ($array as $element) {
$new_array[$element['foo']] = $element;
}
$array = $new_array;
The code is naturally trivial, but I've been wondering whether there's an in-built that can do the same for me.