如果我有这个:
$players = array("A","B","C","D","E","F","G","H","I","J","L","M","N","O","P","Q");
我如何像这样填充单个锦标赛淘汰赛:
Matche 1: AxL
Matche 2: CxJ
Matche 3: HxQ
.
.
.
Matche 8: ExP
16 名玩家 = 8 场比赛
我也试过这个和其他代码:
<?php
$players = array("A","B","C","D","E","F","G","H","I","J","L","M","N","O","P","Q");
shuffle ($players);
foreach($players as $key=>$value)
{
echo $value.','.$value.'<br>';
}
?>
最佳答案
这应该适合你:
只需 shuffle()
您的数组,然后 array_chunk()
将其分成 2 组,例如
<?php
$players = ["A","B","C","D","E","F","G","H","I","J","L","M","N","O","P","Q"];
shuffle($players);
$players = array_chunk($players, 2);
foreach($players as $match => $player)
echo "Match " . ($match+1) . ": " . $player[0] . "x" . $player[1] . "<br>";
?>
关于php - 如何在 PHP 中随机填充单个锦标赛淘汰而不重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30896292/