PHP多维数组提取

时间:2012-08-28 12:07:56

标签: php arrays loops foreach

我试图从foreach循环创建简单数组

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 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:0)

只是循环结果?

$taxon_arg =ptd_get_taxanomies();

foreach($taxon_arg as $arg){
    var_dump($arg);
}