本文实例讲述了PHP实现遍历多维数组的方法。分享给大家供大家参考,具体如下:
array('a'=>'orange','b'=>'grape',c=>'apple'),'numbers'=>array(1,2,3,4,5,6),'holes'=>array('first',5=>'second','third')
);
//第一种:
foreach($a as $list=>$things){
if(is_array($things)){
foreach($things as $newlist=>$counter){
echo "key:".$newlist."
"."value:".$counter."
"; } } } //第二种: function MulitarraytoSingle($array){ $temp=array(); if(is_array($array)){ foreach ($array as $key=>$value ) { if(is_array($value)){ MulitarraytoSingle($value); } else{ $temp[]=$value; } } } }
"."value:".$counter."
"; } } } //第二种: function MulitarraytoSingle($array){ $temp=array(); if(is_array($array)){ foreach ($array as $key=>$value ) { if(is_array($value)){ MulitarraytoSingle($value); } else{ $temp[]=$value; } } } }
希望本文所述对大家PHP程序设计有所帮助。
原文链接:/php/20887.html