I have an array mentioned below.
$array = array(
\'0\' => array(
\'names\' => array(0 => \'Apple\'),
\'group\' => 1
You could iterate the array and store everything in a separate array to the group. Afterwards, you can create the output array in the format you want it, like so:
$groups = array();
foreach($array as $subArray) {
if (!array_key_exists($subArray['group'], $groups)) {
$groups[$subArray['group']] = array();
}
$groups[$subArray['group']] = array_merge($groups[$subArray['group']], $subArray['names']);
}
$result = array();
foreach($groups as $groupId => $group) {
$result[] = array(
'names' => $group,
'group' => $groupId,
);
}
print_r($result);