1.// 给定一个数组$arr = [23,3,45,6,78,8,34],筛选其偶数成员组成新的数组返回,请封装函数。```php
<?php
$arr = [23,3,45,6,78,8,34];
function shaixuan($arr){
foreach($arr as $k =>$v){
if($k % 2 == 0){
$newArr[]=$v;
}
}
return $newArr;
}
var_dump(shaixuan($arr));
?>
2. 尝试实现简单的计算器功能,语言不限制。
```php
<?php
$num1 = $_GET['num1'] ?? '请输入第一个数';
$num2 = $_GET['num2'] ?? '请输入第二个数';
$ysf = $_GET['con'] ?? '请选择运算符';
$result= '';
if (isset($ysf)){
if ($ysf== '*'){
$result = $num1 * $num2;
}
if($ysf == '/'){
if($num2 != 0){
$result = $num1 / $num2;
}else{
$result = '除数不能为零';
}
}
if($ysf == '+'){
$result =$num1 + $num2;
}
if($ysf == '-'){
$result = $num1 - $num2;
}
}
?>
<!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>计算器</title>
</head>
<body>
<form action="" method="get">
<input type="text" name= "num1">
<br>
<select name="con">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
<input type="text" name= "num2" >
<br>
<input type="submit" value="计算">
<br>
</form>
</body>
</html>
<?= $result?>