What are some best practices for automating the creation of a sports league schedule using PHP?

Creating a sports league schedule can be a time-consuming task, especially as the number of teams and games increases. One way to automate this process is by using PHP to generate the schedule based on predefined rules, such as the number of teams, number of games, and scheduling constraints. By writing a script that can dynamically generate the schedule, you can save time and ensure that the schedule is fair and balanced.

<?php
// Define the number of teams
$teams = array('Team A', 'Team B', 'Team C', 'Team D');

// Generate the schedule
$schedule = array();
foreach ($teams as $team1) {
    foreach ($teams as $team2) {
        if ($team1 != $team2) {
            $schedule[] = $team1 . ' vs ' . $team2;
        }
    }
}

// Output the schedule
foreach ($schedule as $game) {
    echo $game . "\n";
}
?>