PHP implements the method of traversing multi-dimensional arrays, PHP traverses multi-dimensional arrays_PHP tutorial

WBOY
Release: 2016-07-12 09:04:09
Original
991 people have browsed it

How to traverse multi-dimensional arrays in php, traverse multi-dimensional arrays in php

The example in this article describes the method of traversing multi-dimensional arrays in php. Share it with everyone for your reference, the details are as follows:

$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

I hope this article will be helpful to everyone in php programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1075075.htmlTechArticleHow to implement traversal of multi-dimensional arrays in php, php traversal of multi-dimensional arrays This article describes the method of traversing multi-dimensional arrays in php. Share it with everyone for your reference, the details are as follows: $a=array('fru...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template