php算法计算案例
php算法计算案例教程分享效果如图所示:
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
if(isset($_POST['button'])){
$jhy = $_POST['diyi'];
$jhe = $_POST['dier'];
$disan = "0";
switch($_POST['suan']){
case '0':
$disan = (int)$jhy + (int)$jhe;
$suan = $_POST['suan'];
break;
case '1':
$disan = $jhy - $jhe;
$suan = $_POST['suan'];
break;
case '2':
$disan =$jhy * $jhe;
$suan = $_POST['suan'];
break;
case '3':
$disan =$jhy / $jhe;
$suan = $_POST['suan'];
break;
}
echo <<<jinhei
<script type="text/javascript">
window.onload=function(){
document.getElementById('disan').value='$disan';
document.getElementById('diyi').value='$jhy';
document.getElementById('dier').value='$jhe';
document.getElementById('suan').value='$suan';
}
</script>
jinhei;
}
?>
<form method="post" action="">
<input type="text" name="diyi" id="diyi">
<select name="suan" id="suan">
<option value="0">+</option>
<option value="1">-</option>
<option value="2">*</option>
<option value="3">/</option>
</select>
<input type="text" name="dier" id="dier">
<input type="submit" name="button" value="=">
<input type="text" value="0" name="disan" id="disan">
</form>
</body>
</html>
页:
[1]