从数组中获取值名称

时间:2015-02-04 10:06:26

标签: php arrays multidimensional-array

我如何得到"名字"来自foreach循环中的数组?

这是我的阵列:

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
        )

)

我试过foreach:

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

但不行,我的问题是:如何从这个数组中获取值名称?

2 个答案:

答案 0 :(得分:3)

尝试 -

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

答案 1 :(得分:2)

你非常接近:

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