2012-08-28 107 views
-1

我尝试创建foreach循环简单数组PHP多维数组提取

function ptd_get_taxanomies(){ 
      foreach ($ptd_taxs as $ptd_tax) { 
       $taxon_arg[] = array(
        'taxonomy' =>$ptd_tax->taxonomy, 
        'field' => 'id', 
        'terms' => $values 
       ); 
      } 
    return $taxon_arg; 
} 

,但它返回我多维数组,

Array 
(
    [0] => Array 
     (
      [taxonomy] => application 
      [field] => id 
      [terms] => 8 

     ) 

    [1] => Array 
    (
     [taxonomy] => dimension 
     [field] => id 
     [terms] => 4 

    ) 

); 

,但是这不是我想要的,我需要一个输出是这样的>

array(
    'taxonomy' => 'application', 
    'field' => 'id', 
    'terms' => '8', 
    ), 
    array(
    'taxonomy' => 'dimension', 
    'field' => 'id', 
    'terms' => '4', 
) 

我该如何删除第一级阵列并得到如上所述的输出

+2

这就是你的本事。你有两个数组,你想返回。你只能返回一个值,所以你必须返回一个包含这些数组的数组。这就是它的工作原理。 – lonesomeday

+0

第二个也是2维数组,你离开的只是你输出中的周围块。否则,你能否澄清你想达到的目标(完成)? – Styxxy

回答

0

只是循环通过结果?

$taxon_arg =ptd_get_taxanomies(); 

foreach($taxon_arg as $arg){ 
    var_dump($arg); 
} 
3
function ptd_get_taxanomies(){ 
    foreach ($ptd_taxs as $ptd_tax) { 
     $taxon_arg = $ptd_tax;    
    } 
    return $taxon_arg; 
}