PHPackages                             mnito/round-robin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mnito/round-robin

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mnito/round-robin
=================

Round-robin schedule generation implementation in PHP

v2.2.0(4y ago)6169.4k↓36.4%15[6 issues](https://github.com/mnito/round-robin/issues)MITPHPPHP &gt;=7.0.0CI failing

Since Sep 8Pushed 4y ago6 watchersCompare

[ Source](https://github.com/mnito/round-robin)[ Packagist](https://packagist.org/packages/mnito/round-robin)[ Docs](https://github.com/mnito/round-robin)[ RSS](/packages/mnito-round-robin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (11)Used By (0)

round-robin
===========

[](#round-robin)

[![Build Status](https://camo.githubusercontent.com/d8788a6ccd360aa5465c00807f32333c52bfab039d0b9499c2862dc43626df0b/68747470733a2f2f6170702e7472617669732d63692e636f6d2f6d6e69746f2f726f756e642d726f62696e2e737667)](https://app.travis-ci.com/mnito/round-robin)

Round-robin schedule generation reference implementation for PHP 7 licensed under the MIT license

Features
--------

[](#features)

- Efficient schedule generation enabled by an efficient round-robin rotation function
- Ability to generate an arbitrary number of rounds
- Support for any number of teams by adding a bye for odd-numbered team counts
- Simple, concise implementation for easy analysis of the algorithm
- Unit tested
- Documented
- Modern PHP 7 code
- Object-oriented and procedural APIs

Basic Usage
-----------

[](#basic-usage)

### Generating Common Schedules

[](#generating-common-schedules)

#### Generate a random schedule where each player meets every other player once:

[](#generate-a-random-schedule-where-each-player-meets-every-other-player-once)

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$schedule = $scheduleBuilder->build();
```

or

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams);
```

#### Generate a random home-away schedule where each player meets every other player twice, once at home and once away, using the $rounds integer parameter:

[](#generate-a-random-home-away-schedule-where-each-player-meets-every-other-player-twice-once-at-home-and-once-away-using-the-rounds-integer-parameter)

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$rounds = (($count = count($teams)) % 2 === 0 ? $count - 1 : $count) * 2;
$scheduleBuilder = new ScheduleBuilder($teams, $rounds);
$schedule = $scheduleBuilder->build();
```

or

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$rounds = (($count = count($teams)) % 2 === 0 ? $count - 1 : $count) * 2;
$schedule = schedule($teams, $rounds);
```

#### Generate a schedule without randomly shuffling the teams using the $shuffle boolean parameter:

[](#generate-a-schedule-without-randomly-shuffling-the-teams-using-the-shuffle-boolean-parameter)

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$scheduleBuilder->doNotShuffle();
$schedule = $scheduleBuilder->build();
```

or

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, false);
```

#### Use your own seed with the $seed integer parameter for predetermined shuffling:

[](#use-your-own-seed-with-the-seed-integer-parameter-for-predetermined-shuffling)

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$scheduleBuilder = new ScheduleBuilder($teams);
$scheduleBuilder->shuffle(89);
$schedule = $scheduleBuilder->build();
```

or

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, true, 89);
```

### Looping Through A Schedule

[](#looping-through-a-schedule)

#### Looping Through the Full Schedule

[](#looping-through-the-full-schedule)

Setup:

```
$teams = ['The 1st', '2 Good', 'We 3', '4ward'];
$schedule = schedule($teams, null, true, 89);
```

or

```
$scheduleBuilder = new ScheduleBuilder();
$scheduleBuilder->setTeams($teams);
$scheduleBuilder->setRounds(10);
$scheduleBuilder->doNotShuffle();
$schedule = $scheduleBuilder->build();
```

Loop through:

```

    Round

         vs.

```

#### Looping Through Team Schedules

[](#looping-through-team-schedules)

```
