forked from fahmad480/PHPSimpleTeamsGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
41 lines (35 loc) · 1.14 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
$persons = isset($_POST['persons']) ? strip_tags($_POST['persons']) : "";
$teamsCount = isset($_POST['teams']) ? strip_tags($_POST['teams']) : 0;
// define our people and teams as simple arrays
// for ($i = 1; $i < 71; $i++) {
// $people[] = "person" . $i;
// }
$people = explode("\n", str_replace("\r", "", $persons));;
for ($i = 1; $i < ($teamsCount + 1); $i++) {
$teams[] = "tim " . $i;
}
shuffle($people);
// what team are we adding to?
$teamidx = 0;
// loop through people, add them to a team
// when you run out of teams, shuffle the team
// order for giggles and start back at the first
// team
for ($i = 0; $i < count($people); $i++) {
$teammembers[$teams[$teamidx]][] = $people[$i];
$teamidx++;
if ($teamidx == count($teams)) {
$teamidx = 0;
shuffle($teams);
}
}
// echo json_encode($teammembers);
for ($i = 1; $i <= count($teammembers); $i++) {
echo "Team " . $i . "\r\n";
for ($j = 0; $j < count($teammembers["tim " . $i]); $j++) {
echo "-" . $teammembers["tim " . $i][$j] . "\r\n";
}
echo "\r\n";
}
echo "Generated by teams generator";