3v4l.org

run code in 300+ PHP versions simultaneously
<?php $results = array ( 0 => array ( "punti" => 418, "vittorie" => 9, "podi" => 18, "gv" => 14, "id_pilota" => 1, "team" => "Red Bull Racing", "naz" => "it" ), 1 => array ( "punti" => 353, "vittorie" => 6, "podi" => 16, "gv" => 3, "id_pilota" => 19, "team" => "Scuderia Ferrari", "naz" => "it" ), 2 => array ( "punti" => 335, "vittorie" => 4, "podi" => 15, "gv" => 1, "id_pilota" => 5, "team" => "Mercedes-AMG", "naz" => "it" ), 3 => array ( "punti" => 181, "vittorie" => 1, "podi" => 5, "gv" => 1, "id_pilota" => 2, "team" => "Mercedes-AMG", "naz" => "it" ), 4 => array ( "punti" => 147, "vittorie" => 0, "podi" => 3, "gv" => 0, "id_pilota" => 14, "team" => "Racing Point F1", "naz" => "mx" ), 5 => array ( "punti" => 127, "vittorie" => 0, "podi" => 0, "gv" => 0, "id_pilota" => 13, "team" => "Haas F1", "naz" => "dk" ) ); $teams = array(); foreach ($results as $result) { $team = $result['team']; if (!isset($teams[$team])) { $teams[$team] = array('team' => $team, 'points' => $result['punti']); } else { $teams[$team]['points'] += $result['punti']; } } $teams = array_values($teams); print_r($teams);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Array ( [0] => Array ( [team] => Red Bull Racing [points] => 418 ) [1] => Array ( [team] => Scuderia Ferrari [points] => 353 ) [2] => Array ( [team] => Mercedes-AMG [points] => 516 ) [3] => Array ( [team] => Racing Point F1 [points] => 147 ) [4] => Array ( [team] => Haas F1 [points] => 127 ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [0] => Array ( [team] => Red Bull Racing [points] => 418 ) [1] => Array ( [team] => Scuderia Ferrari [points] => 353 ) [2] => Array ( [team] => Mercedes-AMG [points] => 516 ) [3] => Array ( [team] => Racing Point F1 [points] => 147 ) [4] => Array ( [team] => Haas F1 [points] => 127 ) )

preferences:
155.33 ms | 403 KiB | 183 Q