作用:遍历数组
- 索引数组
形式:foreach(数组 as 值){
//操作
}
<?phpheader('content-type:text/html;charset=utf-8');$person=array('DL_one',18,'man');foreach($person as $chara){echo $chara,'<br>';}
?>
2. 关联数组
形式:foreach(数组 as $key => $value){
//操作
}
<?phpheader('content-type:text/html;charset=utf-8');$person=array('name'=>'DL_one','age'=>18,'sex'=>'man');foreach($person as $key=>$chara){echo $key,'---',$chara,'<br>';}
?>
当然索引数组也可以用这种形式,键值为0、1、…
<?phpheader('content-type:text/html;charset=utf-8');$person=array('DL_one',18,'man');foreach($person as $key=>$chara){echo $key,'---',$chara,'<br>';}
?>