作业一
<?php
// 方法
$arr=[23,3,45,6,78,8,34,88,23,55];
$newarr=[];
foreach($arr as $key=>$value){
if($key%2==0){
array_push($newarr,$arr[$key]);
}
}
var_dump($newarr);
//封装函数
function getNewArrayByEeven($arr){
$newarr=[];
foreach($arr as $key=>$value){
if($key%2==0){
array_push($newarr,$arr[$key]);
}
}
return $newarr;
}
var_dump(getNewArrayByEeven($arr));
?>
作业二
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简单的计算器</title>
</head>
<body>
<form method="post" action="">
数1:<input type="text", name="n1" />+
数2:<input type="text", name="n2" />=
<input type="submit" name="sub1" value="计算加法" />
<p>
<?php //这段是加法代码段
if(isset($_POST['sub1']))//这是一个点击事件,当点击了sub1时候,执行下面的代码
{
$sub1=$_POST['n1']+$_POST['n2'];//获取将前面的两个框的值,相加赋值给$sub1;
echo $_POST['n1'].'+'.$_POST['n2'].'='.$sub1;//输出结果
}
?>
<p>
<form method="post" action="">
数1:<input type="text" name="n3" />-
数2:<input type="text" name="n4" />=
<input type="submit" name="sub2" value="计算减法" />
<p>
<?php //这段是减法代码段
if(isset($_POST['sub2']))
//点击事件
{
$sub2=$_POST['n3']-$_POST['n4'];//获取相应的值
echo $_POST['n3'].'-'.$_POST['n4'].'='.$sub2;
}
?>
<p>
<form method="post" action="">
数1:<input type="text" name="n5" />*
数2:<input type="text" name="n6" />=
<input type="submit" name="sub3" value="计算乘法" />
<p>
<?php //这是乘法的代码段
if(isset($_POST['sub3'])){
$sub3=$_POST['n5']*$_POST['n6'];
echo $_POST['n5'].'*'.$_POST['n6'].'='.$sub3;
}
?>
<p>
<form method="post" action="">
数1:<input type="text" name="n7" />/
数2:<input type="text" name="n8" />=
<input type="submit" name="sub4" value="计算除法" />
<p>
<?php //这是除法代码段
if(isset($_POST['sub4'] )){
$sub4=$_POST['n7']/$_POST['n8'];
echo $_POST['n7'].'/'.$_POST['n8'].'='.$sub4;
}
?>