实例
<?php //数组的遍历 echo '<fieldset style="width:400px;margin:30px auto;">'; echo '<legend>资料设置</legend>'; echo '<p>性别:'; $sex = ['男', '女', '保密']; foreach ($sex as $value) { echo '<input type="radio" name="sex" id="'.$value.'" value="'.$value.'">'.'<label for="'.$value.'">'.$value.'</label>'.' '; } echo '</p>'; echo '<p>生肖:'; $shuxiang = ['鼠', '牛', '虎', '兔', '龙', '蛇', '马','羊','猴','鸡','狗','猪']; echo '<select name="shuxiang">'; while ($i<count($shuxiang)) { echo '<option value="'.current($shuxiang).'">'.current($shuxiang).'</option>'; next($shuxiang); $i++; } echo '</select>'; echo ' '; echo '血型:'; $xuexing = ['A型', 'B型', 'O型', 'AB型', '其他血型']; echo '<select name="xuexing">'; $i = 0; while ($i<count($xuexing)) { echo '<option value="'.current($xuexing).'">'.current($xuexing).'</option>'; next($xuexing); $i++; } echo '</select></p>'; echo '<p>出生年月:'; echo '<select name="year">'; for ($i=1980; $i<=2015; $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></p>'; echo '<p>请选择你的爱好:</p>'; $hobby = ['编程', '打篮球', '看电影', '骑行','合肥', '南京']; array_splice($hobby, 6); //替换从合肥开始 array_splice($hobby, -2, 3, ['摄影', '下棋', '其他']); //打印 // print_r(array_splice($hobby, -2, 3, ['摄影', '下棋', '其他'])); $i = 0; while($i<count($hobby)) { echo '<input type="checkbox" name="hobby[]" value="'.current($hobby).'">'. current($hobby).' '; next($hobby); $i++; } echo '<br>'; echo '<br><hr>'; echo '<p align="center"><button>关闭</button> <button disabled>保存</button></p>'; echo '</fieldset>';
运行实例 »
点击 "运行实例" 按钮查看在线实例