仅通过多维数组(PHP)中的一个数组循环

时间:2014-09-03 23:09:45

标签: php arrays multidimensional-array

我有一个PHP多维数组,我想只循环遍历一个数组,例如数组“a”或数组“b”有什么建议吗?

Array
(
    [59] => Array
        (
            ["a"] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 59
                            [user_id] => 122
                            [city_id] => 1
                            [country] => 2
                        )
                    [1] => stdClass Object
                        (
                            [id] => 59
                            [user_id] => 123
                            [city_id] => 11
                            [country] => 3
                        )
                )
            ["b"] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 59
                            [user_id] => 124
                            [city_id] => 23
                            [country] => 1
                        )
                )
        )
)

谢谢!

1 个答案:

答案 0 :(得分:3)

您需要访问正确的索引:

foreach($myArray[59]['a'] as $value){

}

for($i = 0; $i < count($myArray[59]['a']); $i++){

// do something with $myArray[59]['a'][$i];
}