Home > php教程 > php手册 > php实现遍历多维数组的方法

php实现遍历多维数组的方法

WBOY
Release: 2018-09-27 11:32:16
Original
946 people have browsed it

这篇文章主要介绍了php实现遍历多维数组的方法,涉及php针对多维数组的遍历与递归操作实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了php实现遍历多维数组的方法。分享给大家供大家参考,具体如下:

$a=array('fruits'=>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."<br/>"."value:".$counter."<br/>";
 }
}
}
//第二种:
function MulitarraytoSingle($array){
   $temp=array();
   if(is_array($array)){
     foreach ($array as $key=>$value )
     {
       if(is_array($value)){
         MulitarraytoSingle($value);
       }
       else{
         $temp[]=$value;
       }
     }
   }
}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template