Problem:
I have a text area in HTML that I wish to input a list of participants into. After submitting the form I would like PHP to take this list and randomise participants into groups of 4. If the participants are uneven (say 51), then the last group should be 3.
Further, I wish to request advice how the participants could be given a title in the output.
Code:
<?php
if (isset($_POST['submit'])) {
$text = trim($_POST['list']);
$array = explode(PHP_EOL, $text);
shuffle($array);
print_r($array);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Randomize groups</title>
<meta charset="UTF-8">
</head>
<body>
<form action="randomize.php" method="post">
<fieldset>
<legend>Randomize groups</legend>
<label for="list">Enter names of participants:</label>
<textarea name="list" rows="12" cols="50" autofocus></textarea>
</fieldset>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Desired output:
Group 1
- Participant 5
- Participant 3
- Participant 7
- Participant 4
Group 2
- Participant 8
- Participant 2
- Participant 1
- Participant 6
Aucun commentaire:
Enregistrer un commentaire