3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "A4 1.9tdi (2003-2009)", "A4 2.0tdi (2003-2009)", "Passat B7 1.9tdi(2003-2009)", "Passat B7 2.0 tdi(2003-2010)" ]; foreach($array as $val){ $temp = explode(" ", $val); $new[$temp[0]][] = $val; } foreach($new as $car => $cars){ echo "<some html tag>". $car . "</Some html tag>\n"; echo "<some other tag>" . implode("</some other tag>\n<some other tag>", $cars) . "</some other tag>\n"; echo "\n"; }

preferences:
31.52 ms | 405 KiB | 5 Q