Blogger Information
Blog 55
fans 0
comment 0
visits 50491
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP利用for循环来遍历关联数组-0824
Bean_sproul
Original
1579 people have browsed it

current()输出数组中的当前元素的值,

key()输出数组中的当前元素的键


实例

<?php 

$arr = ['id'=>1,'name'=>'xiaoyang','age'=>'18','money'=>'1000'];
echo '共有',count($arr),'<hr>';//输出数值数量
echo var_export($arr,'ture'),'<hr>';//输出数组

//使用for()来做遍历关联数组

$a=count($arr);
for ($i=0; $i <$a ; $i++) { 
	echo key($arr),'=>',current($arr);
	next($arr);
	//current()输出数组中的当前元素的值
	//key()输出数组中的当前元素的键
}

 ?>

运行实例 »

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

 

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