Blogger Information
Blog 34
fans 2
comment 2
visits 22719
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
For(), while(),foreach(),实现索引数组,关联数组的遍历20180419-15:39
AsNwds_MIS王的博客
Original
524 people have browsed it

实例

<?php
echo '<h3>数组学习</h3>';
echo '<p>姓名:';
echo '<input type="text">';
echo '</p>';

echo '<p>出生年月:';
$year= range(1970,2010);
echo '<select name="$year">';
foreach ($year as $value) {
	echo '<option value="'.$value.'">'.$value.'</option>';
}
echo '</select>';

echo ' ';

echo '<select name="$month">';
for ($i=01; $i < 13 ; $i++) {
	echo '<option value="'.$i.'">'.sprintf("%02d",$i).'</option>';
}
echo '</select>';
echo ' ';

echo '<select name="$days">';
$i=01; //初始条件
while ( $i<= 31) {//循环条件
	echo '<option value="'.$i.'">'.sprintf("%02d",$i).'</option>';
	$i++;
}
echo '</select>';
echo ' ';

echo '</p>';

运行实例 »

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

无标题.png

For(), while(),foreach()实现数组的遍历 格式如下:

for ($i=0; $i < ; $i++) { 

# code...

}

while ( <= 10) {

# code...

}

foreach ($variable as $key => $value) {

# code...

}


Correction status:qualified

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