* 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',current($teacher),'
'; next($teacher); } echo '
';
//Use while loop to implement
reset($teacher); $i = 0; while ($i',current($teacher),'
'; next($teacher); $i++; } echo '
'; //foreach($arr as $key=>$value):数组专用的遍历语法结构 echo '讲师信息
'; echo ''; foreach ($teacher as $key => $value) { echo '
'; echo '- '.$key.':'.$value.'
'; } echo '
'; //如果只对值感兴趣 echo ''; echo '
'; echo '讲师信息表 '; echo ''; echo ' ID 姓名 工资 课程 '; foreach ($teacher as $value) { echo ' '; echo ''.$value.' '; } echo '
';
//Create a date picker
echo '
Select your birthday:
';//Generate year
$years = range(1980, 2000); echo ''; echo ' ';
//Generation month
$months = range(1, 12); echo ''; echo ' ';
//Generation day
$days = range(1, 31); echo ''; echo ' '; echo '';