Blogger Information
Blog 14
fans 0
comment 0
visits 8670
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
循环for,while,foreach遍历数组 20184.18.15:50
弗洛加特的博客
Original
685 people have browsed it

实例

<?php

$teacher = ['id'=>1001,'name'=>'peter','salary'=>1000,'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="blue">';
reset($teacher);
foreach($teacher as $key => $value){
    echo '['.$key.']=>'.$value.'<br/>';
}


$year = range(1980,2000);
echo '<select name="year">';
foreach($year as $v){
    echo '<option>'.$v.'</option>';
}
echo '</select>';
$months = range(1,12);
echo '<select name="months">';
foreach($months as $v){
    echo '<option>'.sprintf("%02d",$v).'</option>';
}
echo '</select>';
$days = range(1,30);
echo '<select name="days">';
foreach($days as $v){
    echo '<option>'.$v.'</option>';
}
echo '</select>';

运行实例 »

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

QQ截图20180418155413.png

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