Correcting teacher:灭绝师太
Correction status:qualified
Teacher's comments:计算器功能可以完善一下, 比如用户没有输入第一个数,或者除法运算第二个数为0
<?php
//1.给定一个数组$arr = [23,3,45,6,78,8,34],筛选其偶数成员组成新的数组返回,请封装函数。
$arr = [23,3,45,6,78,8,34];
function getArr($arr){
$arr1 = array();
foreach($arr as $k=>$v){
if($v%2==0){
$arr1[$k] = $v;
}
}
return $arr1;
}
echo '<pre>';
print_r(getArr($arr));
界面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>计算器</title>
</head>
<body>
<form action="4.php" method="post">
<span>
<label for="first">第一个数</label>
<input type="text" name="first" id="first"/>
</span>
<span>
<select name="fh" id="">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</span>
<span>
<label for="second">第二个数</label>
<input type="text" name="second" id="second"/>
</span>
<span>=</span>
<span>
<input type="text" value="<?php echo $res ?>">
</span>
<span>
<input type="submit" value="计算">
</span>
</form>
</body>
</html>
php代码功能:
$first = $_POST['first']?? 0;
$second = $_POST['second']?? 0;
$fh = $_POST['fh']?? 0;
switch($fh){
case '+':
$res = $first + $second;
break;
case '-':
$res = $first - $second;
break;
case '*':
$res = $first * $second;
break;
case '/':
$res = $first / $second;
break;
}
include_once ("./jsq.html");