So far I have this to generate random numbers, and I need it to generate random operators, in which it just scrolls through the array and gives off the same 2 operators.
So instead of generating 5 lines it generates about 12. I can get it to show the operator in the math problem but I cannot get the operators to randomize on each line. Something is wrong somewhere.
I also have to have the problem generate in two column table where it has problem in one column and solution in the other. If someone can at least point me in the right direction it would be much appreciated!
<?php
for ($x = 0; $x <= 5; $x++) {
$num1 = mt_rand(1, 9);
$num2 = mt_rand(1, 9);
$operators = array("+","-",);
switch ($operators[array_rand($operators)]) {
case "+":
$result = $num1 + $num2;
break;
case "-":
$result = $num1 - $num2;
break;
}
foreach($operators as $value){
echo "$num1 $value $num2 = $result <br>";
}
}
?>