Crew algemeen |
|
<?php
$playerIds = array(1, 2, 3);
$combinationsPerPlayer = 5;
$combination = array();
foreach ($playerIds as $firstPlayerId) {
foreach ($playerIds as $secondPlayerId) {
if ($firstPlayerId < $secondPlayerId) {
$combination[] = array($firstPlayerId, $secondPlayerId);
}
}
}
$combinations = array();
for ($i = 0; $i < $combinationsPerPlayer; $i++) {
$combinations = array_merge($combinations, $combination);
}
?>
<?php $playerIds = array(1, 2, 3); $combinationsPerPlayer = 5; foreach ($playerIds as $firstPlayerId) { foreach ($playerIds as $secondPlayerId) { if ($firstPlayerId < $secondPlayerId) { $combination[] = array($firstPlayerId, $secondPlayerId); } } } for ($i = 0; $i < $combinationsPerPlayer; $i++) { $combinations = array_merge($combinations, $combination); } ?>
Maakt een array $combinations met daarin steeds een array met eerste en tweede speler. Om de volgorde willekeurig te maken kan je shuffle($combinations); gebruiken. |