Blogger Information
Blog 44
fans 0
comment 1
visits 30977
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
4月17日作业——foreach()的用法
时光记忆的博客
Original
606 people have browsed it

demo4.php

实例

<?php
echo '<h3>常用的数组函数(二)</h3><hr color="green">';

echo '<pre>';
$teacher = ['id'=>5, 'name'=>'peter', 'gender'=>'male', 'age'=>30];
reset($teacher);
$i = 0;
while($i<count($teacher)){
	echo '['.key($teacher),']=>',current($teacher),'<br>';
	next($teacher);
	$i++;
}
echo '<hr color="red">';

//foreach
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">';
//创建一个生日选择器
echo '<p>选择你的生日</p>';
echo '<select name="years">';
$years = range(1980,2000);
foreach($years as $value){
	echo '<option value="'.$value.'" >'.$value.'</option>';
}
echo '</select>';
echo ' ';


$moths = range(1,12);
echo '<select name="moths">';
foreach($moths as $value){
	echo '<option value="'.$value.'" >'.$value.'</option>';
}
echo '</select>';
echo ' ';


$days = range(1,31);
echo '<select name="days">';
foreach($days as $value){
	echo '<option value="'.$value.'" >'.$value.'</option>';
}
echo '</select>';
echo ' ';


echo '<button>提交</button>';

运行实例 »

点击 "运行实例" 按钮查看在线实例

307920039858753348.jpg

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post