Correction status:Uncorrected
Teacher's comments:
for() while() foreach()实现数组的遍历
<?php echo '<h3>数组的遍历</h3><hr color="green">'; echo '<p>请选择你的生日</p>'; echo '<select name="year">'; for ($i=1980; $i<=2000; $i++) { echo '<option value="'.$i.'">'.$i.'</option>'; } echo '</select>'; echo ' '; echo '<select name="month">'; for ($i=1; $i<=12; $i++) { echo '<option value="'.$i.'">'.$i.'</option>'; } echo '</select>'; echo ' '; echo '<select name="day">'; for ($i=1; $i<=31; $i++) { echo '<option value="'.$i.'">'.$i.'</option>'; } echo '</select>'; echo '<p>请选择你的爱好</p>'; $hobby = ['编程', '打篮球', '看电影', '骑行', '摄影', '下棋', '其他']; $i = 0; while($i<count($hobby)) { echo '<input type="checkbox" name="hobby[]" value="'.current($hobby).'">'. current($hobby); next($hobby); $i++; } echo '<p>请选择你的性别</p>'; $sex = ['男', '女', '保密']; foreach ($sex as $value) { echo '<input type="radio" name="sex" value="'.$value.'">'. $value; }
点击 "运行实例" 按钮查看在线实例
效果图:
总结:
foreach($arr as [$key =>] $value){}
while(){}和do{}while()类似
区别在于do{}while()最少执行一次