* 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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.