Blogger Information
Blog 13
fans 0
comment 0
visits 5507
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
for while foreach 数组遍历
安之若素
Original
696 people have browsed it

实例

<?php
  echo '<h2> for,while ,foreach循环语句</h2>';
   $arr=array("name"=>"chjl","sex"=>"boy","age"=>"22") ;
  //for 关联数组遍历
  for($i=0;$i<count($arr);$i++){
	  echo key($arr),'=>',current($arr),'<br/>';
	  next($arr);
	  }
	  reset($arr);
  echo '<hr color="#FF0000">';
  //while 关联数组遍历
  $i=0;
  while($i<count($arr)){
	  
	  echo  key($arr),'=>',current($arr),'<br/>';
	  next($arr);
	  $i++;
	  }
 echo '<hr color="#FF0000">';
  $city =['厦门','广州','上海','深圳','北京','湖北'];
 //for 索引数组
   for ($i=0 ;$i<count($city);$i++){
	echo $city[$i].'<br/>'; 
	   }
	   echo '<hr color="#FF0000">';
 //while 索引数组
  $i=0;
  while($i<count($city)){  
	 echo $city[$i].'<br/>';
	 $i++;
	  }  
	  echo '<hr color="#FF0000">';
  foreach($city as $key=>$value){
	 echo  $key.$value.'<br/>';
	  }
?>

运行实例 »

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

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