<?php
$data = [
['id' => 111, 'text' => 'yellow'],
['id' => 111, 'text' => 'red'],
['id' => 112, 'text' => 'green'],
];
$result = array_map(function($item) {return [
'id' => $item['id'],
'text' => implode(', ', $item['colors']),
];}, array_reduce($data, function($reduced, $item){
if (!isset($reduced[$item['id']])) $reduced[$item['id']] = $item;
$reduced[$item['id']]['colors'][] = $item['text'];
return $reduced;
}, []));
var_dump($result);
preferences:
56.64 ms | 402 KiB | 5 Q