比赛支架算法

i know there's a lot of the same questions out there. This is kind of more specific for this one.

First of all this is all build in PHP. I currently can create the first round but i seem to be having some problems with the ordering and figuring out the algorithm for the placements.

Say if we have 16 players the first round will look like this

1
16

9
8

5
12

13
4

3
14

11
6

7
10

15
2

I can't seem to figure out the algorithm for this thing. So far i make two arrays 1 with the players in ranking order 1 with the number of players and i'm just taking the first, last from the players match them. I need to match this order :/

There are a lot of ways to do this. Consider this as an example:

First create your seed tournament.

$playoff_seed = range(1, 16);
$matchups = array();

// Then get each end of the elements

$x = 0;
while(count($playoff_seed) > 0) {
    $matchups[$x][] = array_shift($playoff_seed);
    $matchups[$x][] = array_pop($playoff_seed);
    $x++;
}

print_r($playoff_seed);

Sample Fiddle