If I wanted to associate items from one array with another array via identical values, eg. items.group_id -> groups.group_id, is there an array function to do that neatly?
I have two arrays:
$items = [
['group_id' => 456, 'item_id' => 123, /* Rest of details */],
['group_id' => 457, 'item_id' => 124, /* Rest of details */],
['group_id' => 457, 'item_id' => 125, /* Rest of details */],
['group_id' => 456, 'item_id' => 126, /* Rest of details */],
];
$groups = [
['group_id' => 456, 'group_name' => 'General'],
['group_id' => 457, 'group_name' => 'Ungeneral'],
];
And the result I want is:
$groups = [
[
'group_id' => 456,
'group_name' => 'General'
[
'item_id' => 123,
// Rest of details
],
[
'item_id' => 126,
// Rest of details
],
],
[
'group_id' => 457,
'group_name' => 'Ungeneral',
[
'item_id' => 124,
// Rest of details
],
[
'item_id' => 125,
// Rest of details
],
],
];