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