Use php to implement addition, subtraction, multiplication and division calculator. The code is very simple!
The code is as follows:
<?php
header(“content-type:text/html;charset=utf-8”);
session_start();
?>
The first number
Calculation symbol
+
–
*
/
The second number
<?php
$num1=$_POST[‘num1’];
$num2=$_POST[‘num2’];
$oper=$_POST[‘oper’];
$rs=0;
switch($oper){
case “+”:
$rs=$num1+$num2;
break;
case “-“:
$rs=$num1-$num2;
break;
case “*”:
$rs=$num1*$num2;
break;
case “/”:
$rs=$num1/$num2;
break;
default: echo “Your input is incorrect”;
}
$_SESSION[‘rs’]=$rs;
echo ‘The calculation result is:’.$_SESSION[‘rs’];
?>
Simple implementation of addition, subtraction, multiplication and division calculator using PHP_PHP
This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/simple-implementation-of-addition-subtraction-multiplication-and-division-calculator-using-php_php/