3v4l.org

run code in 300+ PHP versions simultaneously
<?php $font_f = [ ['font' => 'Poppins', 'lang' => 'Hindi, English', 'weight' => '700, 700i'], ['font' => 'Lora', 'lang' => 'Vietnamese, Japanese', 'weight' => '200, 300, 400, 400i'], ['font' => 'Noto Sans', 'lang' => 'Punjabi, Latin, Hindi', 'weight' => '200, 200i, 300, 300i, 400, 500'], ['font' => 'Lora', 'lang' => 'Greek, Roman, Vietnamese', 'weight' => '400, 400i, 500, 500b'], ]; $result = []; foreach ($font_f as $row) { $f = $row['font']; if (!isset($result[$f])) { $result[$f] = $row; continue; } // append, split, merge, de-duplicate, sort, join foreach(["lang", "weight"] as $col) { $result[$f][$col] .= ', ' . $row[$col]; $result[$f][$col] = array_unique(explode(', ', trim($result[$f][$col], ', '))); sort($result[$f][$col]); $result[$f][$col] = implode(', ', $result[$f][$col]); } } ksort($result); // sort rows by font name var_export(array_values($result)); // print without temporary grouping keys

preferences:
33.53 ms | 411 KiB | 5 Q