我有一个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
)
)
)
)
谢谢!
答案 0 :(得分:3)
您需要访问正确的索引:
foreach($myArray[59]['a'] as $value){
}
或
for($i = 0; $i < count($myArray[59]['a']); $i++){
// do something with $myArray[59]['a'][$i];
}