Home > Backend Development > PHP Tutorial > PHP multidimensional array traversal method (2 implementation methods)_php skills

PHP multidimensional array traversal method (2 implementation methods)_php skills

PHP中文网
Release: 2023-02-28 09:40:01
Original
3056 people have browsed it

The example in this article describes the PHP multi-dimensional array traversal method. Share it with everyone for your reference, the details are as follows:

Method one:

$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."
"."value:".$counter."
";
  }
 }
}
Copy after login

Method two:

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

The above are the PHP multi-dimensional array traversal methods (2 types Implementation method)_php skills content, for more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!

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