Php Learning simple calculator implementation code. For more information, see.
Php Learning simple calculator implementation code. For more information, see.
The Code is as follows:
PHP simple calculator
// Single branch
If (isset ($ _ GET ["sub"])
{
$ Num1 = true; // whether the number 1 is null
$ Num2 = true; // whether the number 2 is null
$ Numa = true; // whether number 1 is a number
$ Numb = true; // whether the number 2 is a digit
$ Message = "";
// Judge whether the number 1 is null
If ($ _ GET ["num1"] = "")
{
$ Num1 = false;
$ Message. = "the first number cannot be blank ";
}
// Determine whether number 1 is a number
If (! Is_numeric ($ _ GET ["num1"])
{
$ Numa = false;
$ Message. = "the first number is not a number ";
}
// Determine whether number 2 is a number
If (! Is_numeric ($ _ GET ["num2"])
{
$ Numa = false;
$ Message. = "the second number is not a number ";
}
// Judge whether number 2 is null
If ($ _ GET ["num2"] = "")
{
$ Num2 = false;
$ Message. = "the second number cannot be blank ";
}
If ($ num1 & $ num2 & $ numa & $ numb)
{
$ Sum = 0;
// Multiple branches
Switch ($ _ GET ["ysf"]) {
Case "+ ":
$ Sum = $ _ GET ["num1"] + $ _ GET ["num2"];
Break;
Case "-":
$ Sum = $ _ GET ["num1"]-$ _ GET ["num2"];
Break;
Case "x ":
$ Sum = $ _ GET ["num1"] * $ _ GET ["num2"];
Break;
Case "/":
$ Sum = $ _ GET ["num1"]/$ _ GET ["num2"];
Break;
Case "% ":
$ Sum = $ _ GET ["num1"] % $ _ GET ["num2"];
Break;
}
}
}
?>