3v4l.org

run code in 300+ PHP versions simultaneously
<?php $the_array = [ ['id' => 1, 'value' => 10, 'name' => 'apple'], ['id' => 1, 'value' => 20, 'name' => 'orange'], ['id' => 1, 'value' => 30, 'name' => 'banana'], ['id' => 2, 'value' => 100, 'name' => 'car'], ['id' => 2, 'value' => 200, 'name' => 'bicycle'], ]; var_export( array_values( array_reduce( $the_array, function ($carry, $row) { if (!isset($carry[$row['id']])) { $carry[$row['id']] = $row; } else { $carry[$row['id']]['value'] += $row['value']; $carry[$row['id']]['name'] .= ",{$row['name']}"; } return $carry; } ) ) );

preferences:
26.72 ms | 406 KiB | 5 Q