PHP switch计算器
程序员文章站
2022-03-06 13:48:39
...
<form action="1.php" method="post">
<input type="number" name="num1" id="num1">
<input type="number" name="num2" id="num2">
<select name="fu">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<button>提交</button>
</form>
<?php
if(!empty($_POST['num1'])){
$num1=floatval($_POST['num1']);
$num2=floatval($_POST['num2']);
$fu=$_POST['fu'];
}
if(!empty($_POST['num1'])){
switch ($fu) {
case '+':
echo $num1+$num2;
break;
case '-':
echo $num1-$num2;
break;
case '*':
echo $num1*$num2;
break;
case '/':
echo $num1/$num2;
break;
}
}
?>
上一篇: 最详尽的 JS 原型与原型链详解
下一篇: uniapp中单选按钮的实现