PHPfor循环遍历一下数组
$students=array('2010'=>array('令狐冲',"59"),'2011'=>array('林平之',"44"),'2012'=>array('曲洋...
$students = array(
'2010'=>array('令狐冲',"59"),
'2011'=>array('林平之',"44"),
'2012'=>array('曲洋',"89"),
'2013'=>array('任盈盈',"92"),
'2014'=>array('向问天',"93"),
'2015'=>array('任我行',"87"),
'2016'=>array('冲虚',"58"),
'2017'=>array('方正',"74"),
'2018'=>array('岳不群',"91"),
'2019'=>array('宁中则',"90"),
);
麻烦for循环一下,然后输出一下,只想要for 展开
'2010'=>array('令狐冲',"59"),
'2011'=>array('林平之',"44"),
'2012'=>array('曲洋',"89"),
'2013'=>array('任盈盈',"92"),
'2014'=>array('向问天',"93"),
'2015'=>array('任我行',"87"),
'2016'=>array('冲虚',"58"),
'2017'=>array('方正',"74"),
'2018'=>array('岳不群',"91"),
'2019'=>array('宁中则',"90"),
);
麻烦for循环一下,然后输出一下,只想要for 展开
展开全部
//只能循环索引数组(下表为0,1,2,3,....)
$arr = array('a','s','d','f','g','h','j','k');
for($i=0;$i<count($arr);$i++){
echo $arr[$i];
}
$arr = array('a','s','d','f','g','h','j','k');
for($i=0;$i<count($arr);$i++){
echo $arr[$i];
}
追问
我想学习一下for循环嵌套for循环,遍历数组嵌套的数组, foreach很好实习,for不会
追答
$arr = array(
'2010'=>array('令狐冲',"59"),
'2011'=>array('林平之',"44"),
'2012'=>array('曲洋',"89"),
'2013'=>array('任盈盈',"92"),
'2014'=>array('向问天',"93"),
'2015'=>array('任我行',"87"),
'2016'=>array('冲虚',"58"),
'2017'=>array('方正',"74"),
'2018'=>array('岳不群',"91"),
'2019'=>array('宁中则',"90"),
);
$k = Array_keys($arr);//获取数组的键名
$arr2 = Array_values($arr);//获取数组的值
$str = null;
for($i=0;$i<count($arr2);$i++){
$new_str = null;
for($n=0;$n<count($arr2[$i]);$n++){
$new_str.= $arr2[$i][$n];
}
$str.= $k[$i].'=='.$new_str."<br>";
}
echo $str;
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询