* 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 id="讲师信息">讲师信息</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 '
Select your birthday:
';//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>';

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
