3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [ 'id' => 10, 'name' => 'John', 'occupation' => 'engineer', 'points' => 10 ], [ 'id' => 10, 'name' => 'John', 'occupation' => 'librarian', 'points' => 14 ], [ 'id' => 7, 'name' => 'Sarah', 'occupation' => 'artist', 'points' => 21 ], [ 'id' => 7, 'name' => 'Sarah', 'occupation' => 'teacher', 'points' => 17 ], [ 'id' => 10, 'name' => 'John', 'occupation' => 'butcher', 'points' => 7 ], [ 'id' => 7, 'name' => 'Sarah', 'occupation' => 'engineer', 'points' => 9 ], [ 'id' => 25, 'name' => 'Andreea', 'occupation' => 'judge', 'points' => 11 ] ]; $result = []; foreach($arr as $v){ $result[$v["id"]][] = $v; } print_r($result);

preferences:
144.86 ms | 404 KiB | 5 Q