用php简单实现加减乘除计算器_php技巧

WBOY
Release: 2016-05-17 08:51:44
Original
1286 people have browsed it

用php实现加减乘除计算器。代码很简单哦!

复制代码 代码如下:

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




简单计算机



第一个数

计算符号

第二个数






$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 "您输入的不正确";
}
$_SESSION['rs']=$rs;
echo '计算结果为:'.$_SESSION['rs'];
?>
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!