user3501587
user3501587

Reputation: 425

Get value name from array

how i can get "name" from array in foreach loop?

This is my array:

Array
(
    [0] => Array
        (
            [term_id] => 2
            [name] => test1
        )

    [1] => Array
        (
            [term_id] => 13
            [name] => test2
        )

    [2] => Array
        (
            [term_id] => 22
            [name] => test3
        )

    [3] => Array
        (
            [term_id] => 19
            [name] => test4
        )

)

i tried with foreach:

foreach ($tags as $get){
    $array[] = array('new' => $get[0]->name);
}

but not work, my question is: how to get value name from this array?

Upvotes: 0

Views: 69

Answers (2)

Daan
Daan

Reputation: 12246

You are very close:

foreach ($tags as $get){
    $array[] = array('new' => $get['name']);
}

Upvotes: 2

Sougata Bose
Sougata Bose

Reputation: 31749

Try with -

foreach ($tags as $get){
    $array[] = array('new' => $get['name']);
}

Upvotes: 3

Related Questions