|
实例如下所示:
"小李","sex"=>"女","age"=>"20");
echo $arr["sex"];
遍历数组
//for循环遍历 适用于索引数组
$arr = [1,5,6,9,4,6,8];
for($i=0;$i"小李","sex"=>"女","age"=>"20");
foreach($arr as $k=>$v){
//echo $k.':'.$v.'
';
echo "{$k}:{$v}
";
};
$arr = [1,5,6,9,4,6,8];
foreach($arr as $k){
echo $k.'
';
};
$arr = array("name"=>"小李","sex"=>"女","age"=>"20");
var_dump(each($arr));
list($a,$b) = array(name,小李);
echo "{$a},{$b}";
list和each结合遍历
/* $arr = array("name"=>"小李","sex"=>"女","age"=>"20");
while(list($k,$v)=each($arr)){
echo "{$k}:{$v}
";
} */
指针遍历
/* $arr = array("name"=>"小李","sex"=>"女","age"=>"20");
echo current($arr);//取value
echo key($arr);//取key
next($arr);
echo current($arr);
echo key($arr);
prev($arr);
echo current($arr);
echo key($arr);
end($arr);
echo current($arr);
echo key($arr);
reset($arr);
echo key($arr).':'.current($arr).'
'; */
|
|