用php循环数组

时间:2016-04-29 09:12:23

标签: php arrays

由于某种原因,我无法使用PHP循环遍历此数组。 我想要循环并回显标题。

这是数组

Array (
[data] => Array
    (
        [0] => Array
            (
                [id] => 1
                [company_id] => 1
                [title] => Software Developer
            )

        [1] => Array
            (
                [id] => 2
                [company_id] => 2
                [title] => Accountant
            )

        [2] => Array
            (
                [id] => 3
                [company_id] => 3
                [title] => Insurance salesman
            )

    )

这是我的代码

    foreach ($positions as $position) {
     echo $position->title;
}

2 个答案:

答案 0 :(得分:3)

用作数组并再多一层

epsg

答案 1 :(得分:2)

这应该有效:

foreach ($positions['data'] as $position) {
     echo $position['title'];
}