—图例
<?php
/*循环
for foreach while do ..while
*/
$cities = ['合肥','南京','苏州','上海','杭州','东莞'];
/*echo current($cities);
next ($cities);
echo current($cities);
next($cities);
echo current($cities);*/
while ( $city=current($cities)):
echo current($cities).'<br>';
//前移针针
next($cities);
endwhile;
//var_dump(current($cities));
reset($cities);
var_dump($cities);
var_dump(count($cities));
//do .. while出口循环
$i=0;
do{
echo $cities[$i];
$i++;
}while($i<count($cities));
echo '<hr>';
//for计算循环 for(初始条件;循环条件;更新条件){满足循环条件所执行的代码块}
for ($i=0;$i<count($cities);$i++){
//break提前结束循环
if($i == 2 ) continue;
echo $cities[$i],'<br>';
}
ob_clean();
/*
* foreach 用于遍历数组
* foreach($array as $value){
* 处理数组成员 $value}
*/
$cities = ['合肥','南京','苏州','上海','杭州','东莞'];
foreach($cities as $vlues ) {
echo "<h1 style='color:pink'><center>$vlues</center></h1>";
};
$info=[['create_time'=>1321657471,'name'=>'peter'],
['create_time'=>1321341451,'name'=>'chloe'],
['create_time'=>1322312471,'name'=>'mile']];
foreach($info as $k =>$v){
$info[$k]['create_time']=date("Y-m-d H:m:s",$v['create_time']);
}
echo '<pre>';
print_r($info);
$info1=[
['贵州'=>'贵阳'],
['贵州'=>'遵义'],
['贵州'=>'安顺']];
foreach($info as $k=>$value){
;
}
print_r($info1);
//作业1 $arr = [23,3,45,6,78,8,34],
$arr = [23,3,45,6,78,8,34];
for($i=0;$i<count($arr);$i++){
if(($arr[$i])%2==0){
$a= "$arr[$i]".',';}
}
—- 计算机器
— 图例
—- 代码区
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form method="post">
<input type="text" name="first" />
<select name="s" id="">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="%">%</option>
<option value="/">/</option>
</select>
<input type="text" name="second">
<input type="submit" value="结果">
</form>
</body>
</html>
<?php
//判断是否PHP的得到值
$first=$_POST["first"]; //获得name为first的值
$v=$_POST["s"]; //获取name为s的值
$second=$_POST["second"]; //获取name为second的值
if($v=="+"){
echo $first."+".$second."结果为".($first+$second);
}elseif($v== "-"){
echo $first."-".$second."结果为".($first-$second);
}elseif($v== "*"){
echo $first."*".$second."结果为".($first-$second);
}elseif($v=="/"){
if($second ==0){
echo "除数不能为0";
}else{
echo $first."/".$second."结果为".($first/$second);
}
}elseif($v == "%"){
if($second ==0){
echo "除数不能为0";
}else{
echo $first."%".$second."结果为".($first%$second);
}
}