I have an array with three elements (round, teamH and teamA). Note that team #1 always appears in the first of any new round.

[round] 1, [teamH] 1, [teamA] 8
[round] 1, [teamH] 2, [teamA] 7
[round] 1, [teamH] 3, [teamA] 6
[round] 1, [teamH] 4, [teamA] 5

[round] 2, [teamH] 1, [teamA] 7
[round] 2, [teamH] 2, [teamA] 8
[round] 2, [teamH] 3, [teamA] 8
[round] 2, [teamH] 4, [teamA] 3
etc

Since these are teams that play every weekend, team number one would be pissed if they always had the 8 am game. I need a way to randomize the games within each round. I inserted a unique, non-repeating randomize number into the mix, figuring I could just sort the array--but here's what's stopping me. I need to sort the 'spot' within in the 'round' without sorting all the 'rounds.'

[spot] 4, [round] 1, [teamH] 1, [teamA] 8
[spot] 3, [round] 1, [teamH] 2, [teamA] 7
[spot] 1, [round] 1, [teamH] 3, [teamA] 6
[spot] 2, [round] 1, [teamH] 4, [teamA] 5

[spot] 1, [round] 2, [teamH] 1, [teamA] 7
[spot] 4, [round] 2, [teamH] 2, [teamA] 8
[spot] 3, [round] 2, [teamH] 3, [teamA] 8
[spot] 2, [round] 2, [teamH] 4, [teamA] 3

etc

So that it looks like this...

[spot] 1, [round] 1, [teamH] 3, [teamA] 6
[spot] 2, [round] 1, [teamH] 4, [teamA] 5
[spot] 3, [round] 1, [teamH] 2, [teamA] 7
[spot] 4, [round] 1, [teamH] 1, [teamA] 8

[spot] 1, [round] 2, [teamH] 1, [teamA] 7
[spot] 2, [round] 2, [teamH] 4, [teamA] 3
[spot] 3, [round] 2, [teamH] 3, [teamA] 8
[spot] 4, [round] 2, [teamH] 2, [teamA] 8

Any ideas. I've scoured the net but couldn't find anything. Could somebody steer me in the right direction?

thanks

    Ah...sometimes you can't see the forest for the big tree blocking the view. The solution is actually pretty simple. So in the incredibly unlikely case that somebody else needs this particular solution--here it is.

    I knew how many matches in each round (let's say 8 teams, giving us four matches in each round. See original thread for more explanation). I created a four number random number for each match within a given round

    $numbers = range($min, $max);

    Then shuffled it:

    shuffle($numbers).

    Let's say it gave the first four matches the slot numbers of 4, 2, 3,1. Increment the $min and $max up by the number of matches in each round (four in this example), so that the next random string might be 5, 7, 6, 8. Feed that entire routine (plus whatever is included in the array) into a fresh array. Be sure that your slot numbers are the first item in the new array. You'll be sorting on that column.

    When all the matches have a slot number, sort the newly created array based on the newly added slot numbers, using array_multisort($newArrayName). This method preserves the individual round integerity, while randomizing the individual matches within each round.

      Write a Reply...