Random NON subteams generator - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Random NON subteams generator.php
- <?php
- $arr = ["Kasia", "Marcin", "Erik", "Wojtek"];
- $teamsNo = 4;
- $shiftMembers = 2;
- $shifts = [];
- for ($i=0; $i < $teamsNo; $i++) {
- shuffle($arr);
- if (!count($shifts)) {
- $shifts[] = [$arr[0],$arr[1]];
- } else {
- $lastShift = $shifts[count($shifts)-1];
- $currentShift = [];
- for ($k=0; $k < count($arr); $k++) {
- if (count($currentShift) == 0 && !in_array($arr[$k], $lastShift)) {
- $currentShift[] = $arr[$k];
- } elseif (count($currentShift) > 0) {
- $currentShift[] = $arr[$k];
- }
- if (count($currentShift) == $shiftMembers) {
- $shifts[] = $currentShift;
- break;
- }
- }
- }
- }
- for ($i =0; $i < count($shifts); $i++) {
- echo 'Week '. ($i+1) . ': ' . $shifts[$i][0] . ' and ' . $shifts[$i][1].PHP_EOL;
- }
File Description
- Random NON subteams generator
- PHP Code
- 18 Oct-2019
- 870 Bytes
You can Share it:
Latest PHP Pastes