Hi Bastadon,
I changed the function code a little so that at least team 1 is shifting from home to away, however it can not avoid that sometimes a team plays home or away twice. To be honest i play competition myself and also from time to time have 2 home or away games after another but you were right about team one, which i corrected with the below code.
I also have a version in which you can send an extra parameter to the function to be able to shuffle the schedule and or create a Home & Return schedule (2-way).
If anyone is interested then let me know and i'll post it as well.
Hope it will suit everones needs!
function scheduler($teams){
if (count($teams)%2 != 0){
array_push($teams,"bye");
}
$away = array_splice($teams,(count($teams)/2));
$home = $teams;
for ($i=0; $i < count($home)+count($away)-1; $i++){
if ($i%2 !=0){
for ($j=0; $j<count($home); $j++){
$schedule[$i][$j]["Home"]=$away[$j];
$schedule[$i][$j]["Away"]=$home[$j];
}
}else {
for ($j=0; $j<count($home); $j++){
$schedule[$i][$j]["Home"]=$home[$j];
$schedule[$i][$j]["Away"]=$away[$j];
}
}
if(count($home)+count($away)-1 > 2){
array_unshift($away,array_shift(array_splice($home,1,1)));
array_push($home,array_pop($away));
}
}
return $schedule;
}