PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I would like to get all the possible combinantions from a pool of teams. For example; there are 3 teams (Chelsea, Arsenal and Man U). I would like to have a script that automatically gives me: Chelsea - Arsenal, Chelsea - Man U, Arsenal - Man U. This is a combination of 2 out of 3. I would like to have code for combinations of 2 out of X (variable number of teams).
$total_teams = count($teamsArray);
// count() inside the for loop will do this:
// call count($teamsArray) as many elements the array has +1 one, and this squared, plus one again
// so it's better outside
for($i=0; $i<$total_teams; $i++) {
for($j=$i+1; $j<$total_teams; $j++) {
echo $teamsArray[$i], " - ", $teamsArray[$j];
}
}