Blogger Information
Blog 28
fans 0
comment 0
visits 14279
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
4.17作业-For(), while(),foreach()的使用方法
泰礴松的博客
Original
520 people have browsed it

进入数组学习,一脸懵逼,加一脸傻逼~~不会,不会,啥也不会,抄抄抄,先抄再背吧~~

实例

<?php
echo '<h3>For(), while(),foreach()的使用方法</h3><hr color="green">';

$teacher = ['id'=>001, 'name'=>'zhang', 'salary'=> 5000, 'course'=>'php'];

for ($i=0; $i<count($teacher); $i++) {
	echo key($teacher),'=>',current($teacher),'<br>';
	next($teacher);
}
echo '<hr color="red">';
reset($teacher);
$i = 0;
while ($i<count($teacher)) {
	echo key($teacher),'=>',current($teacher),'<br>';
	next($teacher);
	$i++;
}

echo '<hr color="red">';
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>';
//生成年
$years = range(1980, 2000);
echo '<select name="year">';
foreach ($years as $value) {
    echo '<option>'.$value.'年</option>';
}
echo '</select>';
echo '  ';


$months = range(1, 12);
echo '<select name="months">';
foreach ($months as $value) {
    echo '<option value='.$value.'>'.sprintf("%02d",$value) .'月</option>';
}
echo '</select>';
echo '  ';

$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>';

运行实例 »

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


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