如何从多维数组中检索值?

时间:2015-07-20 02:46:58

标签: php arrays multidimensional-array

您是否知道如何从此多维数组中检索值(作为字符串)的好方法或提示:

  array (size=5)
  0 => 
   array (size=1)
      'email' => 
       array (size=1)
       0 => string 'lavidabonita@gmail.com' (length=27)
   1 => 
   array (size=1)
  'email' => 
    array (size=1)
      0 => string 'iancasillasbuffon@gmail.com' (length=27)
  2 => 
    array (size=1)
     'email' => 
      array (size=1)
      0 => string 'eddynvg@hotmail.com' (length=19)
  3 => 
    array (size=1)
   'email' => 
    array (size=1)
      0 => string 'dolphin23@dolphin.net' (length=21)
  4 => 
    array (size=1)
   'email' => 
    array (size=1)
      0 => string 'dolphin@dolphin.org' (length=19)

1 个答案:

答案 0 :(得分:1)

试试这个:

function fn($arg){
foreach ($arg as $key => $val){
    if (is_array($val)){
        fn($val);
    }
    else{
        echo "$key : $val\n";
    }
}
}

fn($data);