<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <link rel="icon" href="/favicon.png" /> <title>Esercitazione tabellina</title> </head> <body> <a href=".">Torna indietro</a> <br> <form action="correggi.php"> <?php $source = $_GET["source"] ?? false; if ($source) { highlight_file(__FILE__); return; } $nums = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", ]; $targets = []; foreach ($nums as $num) { $x = $_GET[$num] ?? null; if (isset($x)) { array_push($targets, $num); } } if (count($targets) === 0) { printf("<h1>Nessuna tabellina selezionata!</h1>"); return; } $tests_count = $_GET["tests_count"]; for ($i = 0; $i < $tests_count; $i++) { $x = $targets[array_rand($targets)]; $y = $nums[array_rand($nums)]; printf("<p>%s x %s = <input name=\"%sx%s\" type=\"number\" required></input></p>", $x, $y, $x, $y); } /* foreach ($targets as $target) { foreach (array_rand($nums, 2) as $rand_num) { printf("<p>%s x %s = <input name=\"%sx%s\" type=\"number\" required></input></p>", $target, $rand_num, $target, $rand_num); } }*/ ?> <button type="submit">Correggi</button> </form> </body> </html>