I'm currently working on a kind of PHP Quiz about mathematical calculations. We show a mathematical equation, and user need to input his answer.
Currently, this is what I have written:
echo '<div class="table-title">Super Quizz</div>';
echo '<div class="row text-center quizz">';
function addition($x, $y) { return $x + $y; }
function substraction($x, $y) { return $x - $y; }
function multiplication($x, $y) { return $x * $y; }
function division($x, $y) { return $x / $y; }
do {
$firstNumber = rand(1, 10);
$secondNumber = rand(1, 10);
$operatorsCharacteres = array('+', '-', 'x', '/');
$operatorsLetter = array('addition', 'substraction', 'multiplication', 'division');
$operande = array_rand($operatorsLetter);
$result = call_user_func_array($operatorsLetter[$operande], array($firstNumber, $secondNumber));
}while($result < 0);
echo $firstNumber.' '.$operatorsCharacteres[$operande].' '.$secondNumber.' = <input type="text" name="answer" maxlength="3" class="input-quizz" >';
echo '<input type="hidden" value="'.$result.'">';
echo ' </div>';
echo '<div class="table-title"><a href="#" type="submit">I valid !</a></div>';
echo 'Result : '.$result;
If something is wrong, or not optimised, please, tell me, and teach me.