3v4l.org

run code in 300+ PHP versions simultaneously
<?php $attributes = [ [ "attributeName"=> "Name", "value"=> "Paul" ], [ "attributeName"=> "Name", "value"=> "Steve" ], [ "attributeName"=> "Name", "value"=> "John" ], [ "attributeName"=> "Name", "value"=> "Andrew" ], [ "attributeName"=> "Destination", "value"=> "London" ], [ "attributeName"=> "Destination", "value"=> "Paris" ], [ "attributeName"=> "Destination", "value"=> "Ankara" ], [ "attributeName"=> "Destination", "value"=> "Kuwait" ], ]; $output = array_reduce($attributes, function ($carry, $arr) { $carry[$arr['attributeName']][] = $arr['value']; return $carry; }, array()); print_r($output); echo "<table>\n"; foreach ($output as $key => $values) { echo "<tr><td>$key</td><td>" . implode('</td><td>', $values) . "</td></tr>\n"; } echo '</table>';

preferences:
26.32 ms | 406 KiB | 5 Q