摘要:<?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循環(huán)要對(duì)數(shù)組進(jìn)行遍歷,首先要知道定義變量來獲取數(shù)組的長(zhǎng)度,以用于判斷for循環(huán)循環(huán)幾次,獲取第幾次循環(huán)的值。不同之處在于自動(dòng)+1,for循環(huán)自動(dòng)+1的變量,在于小括號(hào)的條件里面;while循環(huán)自動(dòng)+1的變量,在于大括號(hào)的條件里面;沒有該條件,for會(huì)報(bào)錯(cuò),while會(huì)陷入死循環(huán)
foreach 不用知道數(shù)組的長(zhǎng)度,直接定義變量 $value,就可以對(duì)數(shù)組進(jìn)行遍歷,會(huì)有一個(gè)關(guān)鍵字as
批改老師:查無此人批改時(shí)間:2019-05-16 09:11:31
老師總結(jié):完成的不錯(cuò)。for和while是計(jì)算循環(huán),foreach是數(shù)組循環(huán),繼續(xù)加油