3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[{"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2005-03-27"}, {"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2005-04-13"}, {"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2006-06-07"}, {"REG":"SK", "RES":"PAN2", "WELL":"P2-TG", "TIME":"2009-01-18"}, {"REG":"SK", "RES":"PAN3", "WELL":"P3-TG", "TIME":"2009-03-01"}, {"REG":"SK", "RES":"PAN3", "WELL":"P3-TG", "TIME":"2010-03-14"}]'; foreach (json_decode($json, true) as $row) { $composite_key = implode('-', array_slice($row, 0, 3)); if (!isset($result[$composite_key])) { $row['TIME'] = [$row['TIME']]; $result[$composite_key] = $row; } else { $result[$composite_key]['TIME'][] = $row['TIME']; } } echo json_encode(array_values($result), JSON_PRETTY_PRINT);

preferences:
28.76 ms | 402 KiB | 5 Q