[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: проблемы с массивом
tapok
Помогите разобраться. Нужно,чтобы функция возвращала ассоциативный массив. Где ошибки и как исправить?

<!DOCTYPE html>
<html><head><title>PHP Calculator</title></head>
<form
action="PHP_Calculator.php" method="GET" > <!--method of form submission-->
<lable>Enter the number1 <input TYPE="text" name="a" value="<?php if (!empty($_GET['a'])) {
echo($_GET['a']);
} ?>" /></lable><br><br><!--input parameter-->
<lable>Enter the number2 <input TYPE="text" name="b" value="<?php if (!empty($_GET['b'])) {
echo($_GET['b']);
} ?>" /></lable><br><br>
<lable>
Enter the action: <input TYPE="text" name="operation" value="<?php if (!empty($_GET['operation'])) {
echo($_GET['operation']);
} ?>" /></lable><br><br>
<lable><input
type='submit' name='calculate' value='Calculate'></lable><!--button which sends content-->
</form>
<?php

function
calc($a, $b, $c) {
if (!isset($a) || !isset($b) || !$c) {
var_dump(isset($c), $c);
return false;
}

if (!is_numeric($a) || !is_numeric($b)) {
return false;
}
if (!preg_match("|^[\ + - * \ /]*$|", $c)) {
return false;
}
if ($c == "/") {
if (!$b > 0) {
return false;
}
}

$array1 = array($a, $b, $c);
var_dump($array1);

$array2=array();
$z = $a . $c . $b; {
eval("\$z =$z;");
return $z;
}

$array2['value'] = "$z";
$array2['error1'] = "incorrect format";
$array2['error2'] = "cannot divide";

return $array2;
var_dump($array2);


}

$a = $_GET['a'];
$b = $_GET['b'];
$c = $_GET['operation'];
$tes = calc($a, $b, $c);

if ($tes) {
echo $tes;
} else {
echo '<br><b>Error!</b>';
}

if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['operation']));
if (!preg_match("|^[\d]*[\.,]?[\d]*$|", $_GET['a'])) {
exit("<font color='red'><br>incorrect format!</font>");
} elseif (!preg_match("|^[\d]*[\.,]?[\d]*$|", $_GET['b'])) {
exit("<font color='red'><br>incorrect format!</font>");
} elseif (!preg_match("|^[\ + - * \ /]*$|", $_GET['operation'])) {
exit("<font color='red'><br>incorrect format!</font>");
}
?>
</html>
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2025 Invision Power Services, Inc.