Home  >  Article  >  Backend Development  >  PHP多维数组遍历方法(2种实现方法)_php技巧

PHP多维数组遍历方法(2种实现方法)_php技巧

PHP中文网
PHP中文网Original
2017-03-30 17:50:072917browse

本文实例讲述了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."
"."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多维数组遍历方法(2种实现方法)_php技巧的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

Statement:
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