Hello all!
I'm trying to do a PHP script (and i need to have it done) that makes a schedule of football games of my university.
What i need i need to do is get an array with "n" numbers (team numbers) and match every number with others without repeat.
Confused?
With 8 teams i need 7 weeks.. just like this:
Week 1
8-7
6-5
4-3
2-1
Week 2
8-5
6-3
4-1
2-7
Week 3
8-3
6-1
4-7
2-5
Week 4
8-1
6-7
4-5
2-3
(...)
And here is my code to generate this 4 weeks
/* $week has the inicial schedule (Week 1)
* as a 2D array.. so $week[0][0] would be "8"
* and $week[1][1] would be "5"
*/
function makeSchedule($week) {
$final[0] = $week;
$s = count($week);
for($i=1;$i<$s;$i++) {
for ($l=0;$l<$s-1;$l++) {
$aux = $week[$l][1];
$week[$l][1] = $week[$l+1][1];
$week[$l+1][1] = $aux;
}
$final[$i] = $week;
}
/* returns "final" wich SHOULD be the final
* schedule with 7 weeks (for 8 teams)
*/
return $final;
}
There are 3 missing weeks and those i can't make :mad:
I'm tired of messing arround with arrays! One, two and three dimension arrays! I'm crazy!!!
Please help 🙁
There must be a way to do this 😕
Thank you!