从数组数组获取值 [英] Getting values from array of arrays
本文介绍了从数组数组获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组数组.我正在尝试遍历每个变量并获取值. 这是我用来进入数组的代码,
I have an array of arrays. I am trying to loops through each of it and get values. Here is the code I am using to go into the array,
$body = json_decode($res->getBody(),true); //gets the whole json and make an array
$events = $body['results']; // to go one level down and get 'results'
//var_dump($events);
foreach ($events as $obj) {
var_dump($obj); // to go into the array of arrays and print each inside array.
break;
}
我需要循环的数组:
array(1) {
["events"]=>
array(43) {
[0]=>
array(22) {
["item1"]=>
string(71) "lorem ipsum bla bla"
["lorem ipsum bla bla"]=>
string(21) "lorem ipsum bla bla"
["lorem ipsum bla bla"]=>
string(17) "lorem ipsum bla bla"
["lorem ipsum bla bla"]=>
string(10) "lorem ipsum bla bla"
}
[1]=>
array(22) {
["item1"]=>
string(71) "lorem ipsum bla bla"
["lorem ipsum bla bla"]=>
string(21) "lorem ipsum bla bla"
["lorem ipsum bla bla"]=>
string(17) "lorem ipsum bla bla"
["lorem ipsum bla bla"]=>
string(10) "lorem ipsum bla bla"
}
当我遍历单个项目时数组显示的内容:
它向我展示了完整的阵列
What the array shows when I loop over a single item:
It shows me the complete array
推荐答案
我认为您应该像这样用foreach()
来迭代$events
的 0 索引,
I think you should try like this way with foreach()
to iterate the 0th index of $events
,
foreach($events[0]['events'] as $obj) {
print '<pre>';
print_r($obj);
print '</pre>';
}
这篇关于从数组数组获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文