abstrak:分別用for/while/foreach遍歷數(shù)組 <?php // 創(chuàng)建數(shù)組 $arr =['jack','rose','licen','jary','mary']; print_r ($arr); echo '<hr />'
分別用for/while/foreach遍歷數(shù)組 <?php // 創(chuàng)建數(shù)組 $arr =['jack','rose','licen','jary','mary']; print_r ($arr); echo '<hr />'; //使用for循環(huán)遍歷 $x= count($arr); for ($a=0;$a<$x;$a++) { echo $arr[$a].'<br />'; } echo '<hr />'; // 使用while循環(huán)遍歷 $a=0; while($a<$x){ echo $arr[$a].'<br />'; $a++; } echo '<hr />'; // 使用foreach循環(huán)遍歷 foreach($arr as $b){ print_r ($b); echo '<br />'; } ?>
Guru membetulkan:查無此人Masa pembetulan:2019-03-25 09:09:05
Rumusan guru:完成的不錯。for和while屬于計數(shù)循環(huán),foreach是數(shù)組循環(huán)。牢記它們的使用,繼續(xù)加油