abstract:<?php$min=1;$max=20; $date=range($min, $max); $con=count($date);/*for($i=0;$i<$con;$i++){$res =$date[$i];echo $res.'<hr>';}*//*$n=0;while ($n <$con) {$res =$date[$n];e
<?php
$min=1;
$max=20;
$date=range($min, $max);
$con=count($date);
/*for($i=0;$i<$con;$i++){
$res =$date[$i];
echo $res.'<hr>';
}*/
/*$n=0;
while ($n <$con) {
$res =$date[$n];
echo $res.'<hr>';
$n++;
}*/
foreach ($date as $value) {
echo $value.'<hr>';
}
?>
for,while:for,while循环要对数组进行遍历,首先要知道定义变量来获取数组的长度,以用于判断for循环循环几次,获取第几次循环的值。不同之处在于自动+1,for循环自动+1的变量,在于小括号的条件里面;while循环自动+1的变量,在于大括号的条件里面;没有该条件,for会报错,while会陷入死循环
foreach 不用知道数组的长度,直接定义变量 $value,就可以对数组进行遍历,会有一个关键字as
Correcting teacher:查无此人Correction time:2019-05-16 09:11:31
Teacher's summary:完成的不错。for和while是计算循环,foreach是数组循环,继续加油