Home >Backend Development >PHP Tutorial >Simple implementation of addition, subtraction, multiplication and division calculator using PHP_PHP tutorial

Simple implementation of addition, subtraction, multiplication and division calculator using PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:41:272024browse

Use php to implement addition, subtraction, multiplication and division calculator. The code is very simple!

Copy code The code is as follows:

header("content-type:text/html; charset=utf-8");
session_start();
?>




Simple Computer



No. A number

Calculation symbol

Second number






$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'];
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/676921.htmlTechArticleUse PHP to implement addition, subtraction, multiplication and division calculator. The code is very simple! Copy the code as follows: ?php header("content-type:text/html;charset=utf-8"); session_start(); ? !DOCTYPE html PUBLIC "-/...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn