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."; } ?>

preferences:
64.61 ms | 402 KiB | 5 Q