To implement a calculator, we can use related mathematical operation functions and related arrays in php to perform operations. This person is just fun to write and is not practical. The calculator personally thinks js is the best. To implement a calculator, we can use related mathematical operation functions and related arrays in php to perform operations. This person is just fun to write and is not practical. The calculator personally thinks js is the best.
Script ec (2); script
Php Calculator
| The Code is as follows: |
|
|
PHP simple calculator
$ Num1 = true;
$ Num2 = true;
$ Numa = true;
$ Numb = true;
$ Message = "";
// Single branch
If (isset ($ _ GET ["sub"]) {
If ($ _ GET ["num1"] = ""){
$ Num1 = false;
$ Message. = "the first number cannot be blank ";
}
If (! Is_numeric ($ _ GET ["num1"]) {
$ Numa = false;
$ Message. = "the first number is not a number ";
}
If ($ _ GET ["num2"] = ""){
$ Num2 = false;
$ Message. = "the second number cannot be blank ";
}
If (! Is_numeric ($ _ GET ["num2"]) {
$ Numb = false;
$ Message. = "the second number is not a number ";
}
If ($ num1 & $ num2 & $ numa & $ numb ){
$ Sum = 0;
// Multiple Branch switches
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;
}
}
}
?>
Notice: Undefined index: num1 in
D: \ php \ PHPnow1.5.5 \ Package \ vhosts \ 127.0.0.1 \ ceshi \ jsq. php
On line64
|
Js Calculator
| The Code is as follows: |
|
|
Calculator
Script
Script
|