How to make round robin with 2 arrays
$male = array('peter','john');
$female = array('anna','susan');
Where eg. peter can't talk with john. Only with girls. Here is my working round robin code but only for 1 array
function roundRobin( array $teams ){
if (count($teams)%2 != 0){
array_push($teams,"hold");
}
$away = array_splice($teams,(count($teams)/2));
$home = $teams;
for ($i=0; $i < count($home)+count($away)-1; $i++)
{
for ($j=0; $j<count($home); $j++)
{
$round[$i][$j]["Home"]=$home[$j];
$round[$i][$j]["Away"]=$away[$j];
}
if(count($home)+count($away)-1 > 2)
{
$s = array_splice( $home, 1, 1 );
$slice = array_shift( $s );
array_unshift($away,$slice );
array_push( $home, array_pop($away ) );
}
}
return $round;
}
the output is
Round: 1
peter with susan, john with annaRound: 2 peter with john, susan with anna etc....