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 = array(
[0] => array(
'group_id' => 456,
'item_id' => 123,
// Rest of details
);
[1] => array(
'group_id' => 457,
'item_id' => 124,
// Rest of details
);
[2] => array(
'group_id' => 457,
'item_id' => 125,
// Rest of details
);
[3] => array(
'group_id' => 456,
'item_id' => 126,
// Rest of details
);
);
$groups = array(
[0] => array(
'group_id' => 456,
'group_name' => 'General'
);
[1] => array(
'group_id' => 457,
'group_name' => 'Ungeneral'
);
);
And the result I want is:
$groups = array(
[0] => array(
'group_id' => 456,
'group_name' => 'General'
[0] => array(
'item_id' => 123,
// Rest of details
);
[1] => array(
'item_id' => 126,
// Rest of details
);
);
[1] => array(
'group_id' => 457,
'group_name' => 'Ungeneral'
[0] => array(
'item_id' => 124,
// Rest of details
);
[1] => array(
'item_id' => 125,
// Rest of details
);
);
);
It's probably not too complicated, but I was hoping there would be a neat solution already implemented in PHP! Many thanks for any help.