3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['group' => 'A', 'name' => 'Ann', 'age' => 19], ['group' => 'B', 'name' => 'Bea', 'age' => 26], ['group' => 'A', 'name' => 'Cam', 'age' => 32], ['group' => 'B', 'name' => 'Des', 'age' => 24] ]; $result = []; foreach ($array as ['group' => $group, 'group' => $result[$group]['group'], 'name' => $name, 'age' => $result[$group][$name]]); var_export($result);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.26, 8.1.0 - 8.1.13
array ( 'A' => array ( 'group' => 'A', 'Ann' => 19, 'Cam' => 32, ), 'B' => array ( 'group' => 'B', 'Bea' => 26, 'Des' => 24, ), )

preferences:
41.25 ms | 409 KiB | 5 Q