I started learning and I am making a project for a home fifa18 cup. I have one problem, I don't know how I can pair all players I mean: Player1, Player2, Player3, Player4
=> P1 vs P2, P1 vs P3, P1 vs P4
=> P2 vs P3, P2 vs P4
=> P3 vs P4
I use Newton formula n!/k!(n-k)!
to count how many match without revenge will be and have all players in $tab
.
So now, my question, how can I pair this?
Like that and it will be not repetition & P1 vs P1 example.
<?php
require("server/baza.php");
$przelacznik = 1;//$_POST['losuj'];
$zapytanie = "select nick from mecze";
if($przelacznik == 1){
$wynik = mysqli_query($polaczenie,$zapytanie);
$tab = array();
$n=0;
while($wiersz = mysqli_fetch_assoc($wynik)){
array_push($tab,$wiersz['nick']);
//$tab[] = $wiersz;
$n++;
}
$Nsilnia = 1;
$NKsilnia =1;
for ($i=1; $i<=$n; $i++) {
$Nsilnia *= $i;
}
for($j=1;$j<=($n-2);$j++){
$NKsilnia *= $j;
}
$ilosc_rozgrywek = ($Nsilnia)/(2*$NKsilnia);
}
?>