hi guys my function is below, the function works fine,
however it does not push $result onto the end of my
$answers array.
basically it should print some simple randomly generated
math problems for my son, and print the answers at the bottom
of the page.
the actual working script does add,sub(and mult and div):
[url]http://www.marketing-etcetera.com/math/2-digits.php
but i don’t want the answers to print under the problems,
i want it to add them to an $answers array and then print
the answers array in fine print along with the corresponding
problem number(i can handle this), but i can’t get the function
to push the $result onto the $answers array.
this is a scaled down version of the script and the script follows below….
[url]http://www.marketing-etcetera.com/math/test.php
by the way array_push() does work but just not from within the function.
thanks for responding!
<?
$answers = array();
function do_math(){
$pick1 = rand(0,99);
$pick2 = rand(0,99);
$result = $pick1 + $pick2;
echo “
$pick1<br>+ $pick2<br>________<br>$result
“;
array_push($answers,$result);
}
?>
<table align=”center” cellspacing=”10″>
<tr align=’right’>
<td><? do_math(); ?></td>
<td><? do_math(); ?></td>
<td><? do_math(); ?></td>
<td><? do_math(); ?></td>
<td><? do_math(); ?></td>
</tr>
</table>
<? print_r($answers); ?>