Let me says this up front, I am not trying to get every combination.
I am trying to get every combination of 6 players per team without each player being on a new team with another player from their original team. example
$team1 = "John, Joey, Steve, Lee";
$team2 = "Tom, Alex, Billy";
$team3 = "Clint";
$team4 = "Alan, Jerry";
...
$team10 = "James, Corey, Paul, Benny";
John and Joey can not be in the future combinations; Tom and Billy cannot be in any future combinations together. But I am trying to get every combination of 1 player from each of the 10 teams. I have all ten teams in an associative array $team
I have been trying to use this function but I think I am on the wrong track.
function combinations($arrays, $i = 0) {
if (!isset($arrays[$i])) {
return array();
}
if ($i == count($arrays) - 1) {
return $arrays[$i];
}
// get combinations from subsequent arrays
$tmp = combinations($arrays, $i + 1);
$result = array();
// concat each array from tmp with each element from $arrays[$i]
foreach ($arrays[$i] as $v) {
foreach ($tmp as $t) {
$result[] = is_array($t) ?
array_merge(array($v), $t) :
array($v, $t);
}
}
return $result;
}
print_r(
combinations(
array(
$team[1],
$team[2],
$team[3],
$team[4],
$team[5],
$team[6],
$team[7],
$team[8],
$team[9],
$team[10]
)
)
);