This is a script designed to run a list of arithmetic functions. It is for a math game where one rolls 3 dice to get a number then roll them again to get 3 numbers that using roots, multiplication, addition, subtraction, division, and exponents. When I input the numbers I get back a blank page. Thanks to all who help.
<?php
$functions = array(
"$a+$b+$c",
"$a+$b-$c",
"$a+$b*$c",
"$a+$b/$c",
"$a+$b^(1/$c)",
"$a+$b^$c",
"$a+^($b+$c)",
"$a+^($b-$c)",
"$a+^($a*$c)",
"$a+^($b/$c)",
"$a+^($b^(1/$c))",
"$a+^($b^$c)",
"$a+^(1/($b+$c))",
"$a+^(1/($b-$c))",
"$a+^(1/($a*$c))",
"$a+^(1/($b/$c))",
"$a+^(1/($b^(1/$c)))",
"$a+^(1/($a^$c))");
if(!$_POST['A'])
{
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
Target:<input name="Target" type="text" size="20" maxlength="4">
Number 1:<input name="A" type="text" size="20" maxlength="2">
Number 2:<input name="B" type="text" size="20" maxlength="2">
Number 3:<input name="C" type="text" size="20" maxlength="2">
<input type="submit" name="Send" value="submit">
</form>
<?php
}
else
{
$target = $_POST['Target'];
$a = $_POST['A'];
$b = $_POST['B'];
$c = $_POST['C'];
$nums = array(brute($a, $b, $c));
array_push ($num, brute($a, $c, $b));
array_push ($num, brute($b, $a, $c));
array_push ($num, brute($b, $c, $a));
array_push ($num, brute($c, $a, $b));
array_push ($num, brute($c, $b, $a));
$results = compare($nums, $target);
while (list($pos, $result) = each($results))
{
echo($result['result']);
echo($result['function']);
}
}
function brute($a, $b, $c)
{
$array = array();
while(list($pos, $function) = each($functions))
{
$array2 = array
(
"result"=>sprintf($function),
"function"=>$function
);
array_push($array, $array2);
}
return($array);
}
function compare($arrays, $target)
{
while(list($pos, $array)= each($arrays))
{
$diffs = array();
array_push($diffs, $target - $array['result']);
}
$mins = min(diffs);
while (list($pos, $min) = each( $mins))
{
$results = array();
while (list($pos, $diff)= each($diffs))
{
if ($min = $diff['result'])
{
array_push($results, $diff);
}
}
}
return ($results);
}