用php简单实现加减乘除计算器_PHP教程
程序员文章站
2022-04-10 15:53:20
...
用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'];
?>
复制代码 代码如下:
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'];
?>
上一篇: 利用Tp删除栏目