3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ranking ($players_scores) { $players = array_column($players_scores, 0); $scores = array_column($players_scores, 1); array_multisort($scores, SORT_DESC, $players, SORT_ASC, $players_scores); return $players_scores; } function round_system ($players_scores) { $players_count ($players_scores); return round_count_system ($players_count); } function round_count_system ($players_count) { if ($players_count < 2) return no_match ($players_count); if ($players_count <= 5) return everybody_battles_everybody ($players_count); if ($players_count == 8) return groups_with_N_players (4, (int)($players_count/4)); if ($players_count % 4 == 0 && $players_count/4<=5) return four_groups ((int)($players_count/4)); if ( ($players_count % 6 == 0) && (3<=$players_count/6) && ($players_count/6<=5) ) return groups_with_N_players ((int)($players_count/6), 6); if ($players_count % 3 == 0) return groups_with_N_players (3, (int)($players_count/3)); if ($players_count % 2 == 0 && $players_count<=12) return groups_with_N_players ((int)($players_count/2), 2); echo swiss_round ($players_count); } /* */ /* $ranking = ranking ($players_scores); var_dump ($ranking); echo "<br><br>"; */ $players_scores = [ [1,0], [2,0], [3,0], [4,0], [5,0], [6,0], [7,0], [8,0] ]; $max_players = 30; for ($i=0;$i<=$max_players;$i++) { echo $i." = "; $system = round_count_system ($i); echo "\n"; } function no_match ($players_count) { echo "No match!"; } function everybody_battles_everybody ($players_count) { echo "Every player battles the other players."; } function four_groups ($players_count) { echo "4 groups with ".$players_count." players each."; } function groups_with_N_players ($n, $players_count) { echo $players_count." "."groups with ".$n." players each."; } function swiss_round ($players_count) { echo "swiss system with "; echo floor (log ($players_count, 2))+1; echo " rounds. "; if ($players_count%2) echo "Some players play only ".floor (log ($players_count, 2))." matchs."; } ?>
Output for 7.1.25 - 7.1.30, 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.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
0 = No match! 1 = No match! 2 = Every player battles the other players. 3 = Every player battles the other players. 4 = Every player battles the other players. 5 = Every player battles the other players. 6 = 2 groups with 3 players each. 7 = swiss system with 3 rounds. Some players play only 2 matchs. 8 = 2 groups with 4 players each. 9 = 3 groups with 3 players each. 10 = 2 groups with 5 players each. 11 = swiss system with 4 rounds. Some players play only 3 matchs. 12 = 4 groups with 3 players each. 13 = swiss system with 4 rounds. Some players play only 3 matchs. 14 = swiss system with 4 rounds. 15 = 5 groups with 3 players each. 16 = 4 groups with 4 players each. 17 = swiss system with 5 rounds. Some players play only 4 matchs. 18 = 6 groups with 3 players each. 19 = swiss system with 5 rounds. Some players play only 4 matchs. 20 = 4 groups with 5 players each. 21 = 7 groups with 3 players each. 22 = swiss system with 5 rounds. 23 = swiss system with 5 rounds. Some players play only 4 matchs. 24 = 6 groups with 4 players each. 25 = swiss system with 5 rounds. Some players play only 4 matchs. 26 = swiss system with 5 rounds. 27 = 9 groups with 3 players each. 28 = swiss system with 5 rounds. 29 = swiss system with 5 rounds. Some players play only 4 matchs. 30 = 6 groups with 5 players each.

preferences:
163.92 ms | 406 KiB | 165 Q