abstrait:分別用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 />'; } ?>
Professeur correcteur:查無(wú)此人Temps de correction:2019-03-25 09:09:05
Résumé du professeur:完成的不錯(cuò)。for和while屬于計(jì)數(shù)循環(huán),foreach是數(shù)組循環(huán)。牢記它們的使用,繼續(xù)加油