PHP switch计算器
程序员文章站
2022-02-14 11:18:47
...
<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;
}
}
?>