Created
September 1, 2018 07:49
-
-
Save makzan/5f11851c0c3b51a33e167b9ae3d4e0de to your computer and use it in GitHub Desktop.
Example code for PHP class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// DATA | |
$questions=[]; | |
$questions[] = [ | |
"q" => "1+2", | |
"ans" => "3" | |
]; | |
$questions[] = [ | |
"q" => "3x5", | |
"ans" => "15" | |
]; | |
$questions[] = [ | |
"q" => "6/2", | |
"ans" => "3" | |
]; | |
$questions[] = [ | |
"q" => "3-5", | |
"ans" => "-2" | |
]; | |
// LOGIC | |
$currentNum = $_POST["num"] ?? 0; | |
$q = $questions[$currentNum]; | |
if (isset($_POST["ans"])) { | |
if ($_POST["ans"] == $q["ans"]) { | |
$currentNum += 1; | |
$q = $questions[$currentNum]; | |
} | |
} | |
?> | |
<form action="" method="POST"> | |
<h1><?= $q["q"] ?></h1> | |
Your answer:<br> | |
<input type="text" name="ans" autofocus> | |
<input type="hidden" name="num" value="<?= $currentNum ?>"> | |
<input type="submit"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment