abstrak:<?php$data = range(1,20);$count = count($data);//用for循環(huán)依次輸出$data數(shù)組的值/*for ($i=0; $i<$count; $i++) { echo $data[$i] . '<br>';}*///用while()循環(huán)輸出$data數(shù)組的值/*$i = 0;while ($
<?php $data = range(1,20); $count = count($data); //用for循環(huán)依次輸出$data數(shù)組的值 /*for ($i=0; $i<$count; $i++) { echo $data[$i] . '<br>'; }*/ //用while()循環(huán)輸出$data數(shù)組的值 /*$i = 0; while ($i < $count) { echo $data[$i] . '<br>'; $i++; }*/ //用do while()輸出$data數(shù)組的值,這個循環(huán)是不管條件成不成立,都會執(zhí)行一次循環(huán)體內(nèi)的語句 /*$i = 0; do { echo $data[$i] . '<br>'; $i++; } while($i < $count);*/ //用foreach 來循環(huán)輸出$data數(shù)組的值: 這個是專門用來遍歷數(shù)組的循環(huán) foreach ($data as $key => $value) { echo '$data數(shù)組的鍵是:' . $key . ' 值是:' . $value . '<br>'; }
Guru membetulkan:查無此人Masa pembetulan:2019-03-15 09:14:12
Rumusan guru:完成的不錯。foreach 可以循環(huán)關(guān)聯(lián)數(shù)組,其他的循環(huán)屬于計數(shù)循環(huán)。繼續(xù)加油