* Array traversal
* 1. foreach($arr as $key => $value) {}
* 2. Principle: Array $arr according to key value pair in sequence Take it out into $key=>$value and process it one by one, similar to callback
* 3. If you only process the value, you can omit $key: foreach($arr as $value) {}
* 4. Especially suitable for associative arrays, of course also suitable for index arrays
$teacher = ['id'=>1001, 'name'=>'peter zhu', 'salary'=> 3000, 'course'=>'php'];
//Use for loop to implement traversal of associative array
for ($i=0; $i<count($teacher); $i++) { echo key($teacher),'=>',current($teacher),'<br>'; next($teacher); } echo '<hr color="red">';
//Use while loop to implement
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>'; foreach ($teacher as $value) { echo '<td align="center">'.$value.'</td>'; } echo '</tr>'; echo '</table>'; echo '<hr color="red">';
//Create a date picker
echo 'e388a4556c0f65e1904146cc1a846beeSelect your birthday:94b3e26ee717c64999d7867364b1b4a3';
//Generate year
$years = range(1980, 2000); echo '<select name="year">'; foreach ($years as $value) { echo '<option>'.$value.'年</option>'; } echo '</select>'; echo ' ';
//Generation month
$months = range(1, 12); echo '<select name="months">'; foreach ($months as $value) { echo '<option value='.$value.'>'.sprintf("%02d",$value) .'月</option>'; } echo '</select>'; echo ' ';
//Generation day
$days = range(1, 31); echo '<select name="days">'; foreach ($days as $value) { echo '<option value='.$value.'>'.sprintf("%02d",$value) .'日</option>'; } echo '</select>'; echo ' '; echo '<button>提交</button>';