Correction status:qualified
Teacher's comments:
一、代码案例及演示:
<?php header("Content-type:text/html;charset=utf-8"); for ($i=0; $i<10; $i++) { echo $i<9 ? $i. ',' : $i; } echo "<hr>"; $i = 0; while ($i <= 10) { echo $i<9 ? $i.',' : $i; $i++; } echo '<hr>'; echo '<pre>'; $user = ['name'=>'hah', 'id'=>5, 'sex'=>'男']; print_r($user); echo '<hr color="red">'; echo in_array('hah',$user) ? '存在<br>' : '不存在'; echo '<hr>'; $teacher = ['id'=>1, 'name'=>'王强', 'salary'=> 3000, 'course'=>'java']; //用for循环来实现关联数组的遍历 for ($i=0; $i<count($teacher); $i++) { echo key($teacher),'=>',current($teacher),'<br>'; next($teacher); } echo '<hr color="red">'; //用while循环来实现 reset($teacher); $i = 0; while ($i<count($teacher)) { echo key($teacher),'=>',current($teacher),'<br>'; next($teacher); $i++; } echo '<hr color="red">'; //foreach($arr as $key=>$value):数组专用的遍历语法结构 echo '<h4>工资列表</h4>'; echo '<ul>'; foreach ($teacher as $key => $value) { echo '<li>'.$key.':'.$value.'</li>'; } echo '</ul>'; echo '<hr color="red">'; //如果只对值感兴趣 echo '<table border="1" cellpadding="3" cellspacing="0" width="300">'; echo '<caption>信息列面</caption>'; echo '<tr bgcolor="lightskyblue"><th>ID</th><th>姓名</th><th>工资</th><th>工时</th></tr>'; echo '<tr>';
点击 "运行实例" 按钮查看在线实例