Maybe this code solve your problem, it is not as elegant as it could be but it seems to work.
You should know ho arrangeGames works ;)
Maybe you need to pay attention on arrangePlayerforDays. It put the various games in a day only if both of the players don't have a game already scheduled on that day.
The other function are just for make the code more readable (and cover a pair of glitches in arrangePlayerforDays)
function gamePrettyPrint($gamesOnADay, $glue) {
$result=array();
foreach ($gamesOnADay as $currentGame)
$result[]=join($glue,$currentGame);
return $result;
}
function arrangeGamesOnAday($day) {
$result=array();
for ($k=0, $limit=count($day); $k<$limit; $k+=2)
$result[]=array($day[$k+1], $day[$k]);
return $result;
}
function arrangeGames($players) {
for ($i=0, $limit=count($players); $i < $limit; $i++)
for ($j=$i+1; $j<$limit;$j++)
$games[]=array($players[$i], $players[$j]);
return $games;
}
function calculateTournamentDuration($players) {
return count($players)-1; // (n!)/(2!*(n-2)!) * (1/n)
}
function arrangePlayerforDays($games, $days) {
$mem = array_pad(array(),$tournamentDays,array());
for ($k=0;count($games);$k++)
if ((array_search($games[0][0],$mem[$k%$days])=== false) and
(array_search($games[0][1],$mem[$k%$days])=== false))
list($mem[$k%$days][], $mem[$k%$days][]) = array_shift($games);
return ($mem);
}
function scatterGamesOnCalendar($games, $tournamentDays) {
$days=arrangePlayerforDays($games, $tournamentDays);
$calendar=array_map('arrangeGamesOnAday',$days);
return $calendar;
}
// $initialArray = array('a','b','c','d','e','f','g','h');
$initialArray = array(30,31,32,33,34,35);
$games= arrangeGames($initialArray);
$tournamentSpan = calculateTournamentDuration($initialArray);
$calendar = scatterGamesOnCalendar($games, $tournamentSpan);
while ($day=array_shift($calendar))
$prettyCalendar[]=gamePrettyPrint($day,' v ');
print_r($prettyCalendar);