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
Release: 2016-07-13 10:41:27
Original
2002 people have browsed it

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 "-/...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template