Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
作业标题:0805 PHP编程作业
作业内容:1.给定一个数组$arr = [23,3,45,6,78,8,34],筛选其偶数成员组成新的数组返回,请封装函数。 2. 尝试实现简单的计算器功能,语言不限制。
<?php
$arr = [23,3,45,6,78,8,34];
$arr1=[];
function arr($arr,$arr1)
{
for ($i = 0; $i <count($arr);$i++){
//print($arr[$i]);
if(($arr[$i]%2)==0){
array_push($arr1,$arr[$i]);
}
echo "<br>";
}
print_r($arr1);
}
arr($arr,$arr1);
尝试实现简单的计算器功能,语言不限制
<!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>
<link
href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.css"
rel="stylesheet"
/>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.bundle.js"></script>
<style>
* {
background-color: #d4edda;
text-align: center;
font-size: 20px;
}
.form-control {
width: 500px;
padding: 0.375rem 0.75rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: 0.25rem;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.col-md-2 {
padding-left: 0;
padding-right: 0;
}
button {
width: 242px;
}
</style>
</head>
<body>
<h2 class="title">计算器</h2>
<div class="d-flex h-100">
<div class="m-auto">
<form action="" style="align-content: center" onsubmit="return false;">
<div class="form-group">
<label class="col-md-2 control-label">第一个数</label>
<div class="col-md-6">
<input type="text" class="form-control" id="111" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">第二个数</label>
<div class="col-md-6">
<input type="text" class="form-control" id="222" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">选择运算符</label>
<div class="col-md-12">
<select id="123">
<option id="11">+</option>
<option id="12">-</option>
<option id="13">*</option>
<option id="14">/</option>
<option id="15">%</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label"></label>
<div class="col-md-12">
<button class="btn btn-primary btn btn-default btn-lg">
运算结果
</button>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label"></label>
<div class="col-md-6">
<input type="text" class="form-control" id="lat" />
</div>
</div>
</form>
</div>
</div>
<div id="msg" style="margin-top: 20px; color: Red; display: none"></div>
</body>
<script>
let a1;
let b1;
$("button").click(function () {
a1 = $("#111").val();
b1 = $("#222").val();
//取运算符
let run = $("#123 option:selected").val();
alert(run);
switch (run) {
case "+":
$("#lat").val(add(a1, b1));
break;
case "-":
$("#lat").val(subtract(a1, b1));
break;
case "*":
$("#lat").val(ride(a1, b1));
break;
case "/":
$("#lat").val(devide(a1, b1));
break;
case "%":
$("#lat").val(mod(a1, b1));
break;
}
});
//加法
function add(a1, b1) {
return a1 * 1 + b1 * 1;
}
//减法
function subtract(a1, b1) {
return a1 * 1 - b1 * 1;
}
//乘法
function ride(a1, b1) {
return a1 * b1;
}
//除法
function devide(a1, b1) {
if (a1 == 0) {
alert("请输入不为0的数字");
$("#111").val("");
$("#lat").val("");
$("#111").focus();
} else {
return a1 / b1;
}
}
//取余
function mod(a1, b1) {
return a1 % b1;
}
</script>
</html>