Blogger Information
Blog 38
fans 0
comment 1
visits 30397
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
For(), while(),foreach(),实现数组的遍历
1
Original
561 people have browsed it

实例

<?php 

echo '<pre>';
$arr = [3,5,4,10,'a'=>'jojo',39,'mysql',true];
print_r($arr);
echo '<hr>';

// for循环遍历
for ($i=0; $i <count($arr) ; $i++) { 
	echo key($arr),'=>',current($arr),'<br>';
	next($arr);
}
reset($arr);
echo "<hr>";
// while循环
$i=0;
while ($i<count($arr)) {
	echo key($arr),'=>',current($arr),'<br>';
	next($arr);
	$i++;
}
echo "<hr>";
reset($arr);
// foreach
foreach ($arr as $key => $value) {
	echo $key.'=>'.$value.'<br>';
}
 ?>

运行实例 »

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

微信图片_20180426133613.jpg

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
  • 1
    2018-03-16 00:39:40
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!