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
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 0 => array ( 'font' => 'Lora', 'lang' => 'Greek, Japanese, Roman, Vietnamese', 'weight' => '200, 300, 400, 400i, 500, 500b', ), 1 => array ( 'font' => 'Noto Sans', 'lang' => 'Punjabi, Latin, Hindi', 'weight' => '200, 200i, 300, 300i, 400, 500', ), 2 => array ( 'font' => 'Poppins', 'lang' => 'Hindi, English', 'weight' => '700, 700i', ), )

preferences:
48.16 ms | 407 KiB | 5 Q