-1

im trying to create simple array from foreach loop

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

, but it returns me multidimensional array,

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

        )

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

    )

);

but this is not that i want, i need an output like this >

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

how do i remove the first level array and get the output like above

2
  • 2
    That's what you've got. You have two arrays, which you want to return. You can only return one value, so you have to return an array containing those arrays. That's how it works. Aug 28, 2012 at 12:09
  • The second one is also a 2 dimensional array, all you leave is the surrounding block in your output. Or else, can you please clarify of what you would like to achieve (get done)?
    – Styxxy
    Aug 28, 2012 at 12:10

2 Answers 2

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

Just loop through the result?

$taxon_arg =ptd_get_taxanomies();

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.