I'm trying to get information from the $array1 below.
我正在尝试从下面的$ array1获取信息。
I'm getting with no problems venue's name and location address by doing:
我通过以下方式获得场地的名称和位置地址没有问题:
$array2 = array();
$array3 = array();
foreach($array1 as $item){
$array2[] = $item->venue->name;
$array3[] = $item->venue->location->address;
}
But now I need to get the photos url and I don't know how to do it.
但现在我需要获取照片网址,我不知道该怎么做。
Thanks a million!
太感谢了!
$array1:
Array
(
[0] => stdClass Object
(
[venue] => stdClass Object
(
[name] => a name
[location] => stdClass Object
(
[address] => main street
)
)
[photos] => stdClass Object
(
[count] => 1
[items] => Array
(
[0] => stdClass Object
(
[url] => http://folder/photo1.jpg
.
.
)))
.
.
3 个解决方案
#1
2
$array1[0]->photos->items[0]->url
Remember - you access arrays with [index]
parenthesis, objects with ->
arrows.
记住 - 使用[index]括号访问数组,使用 - >箭头访问对象。
#2
1
Untested code:
$array2 = array();
$array3 = array();
$photos = array();
foreach($array1 as $item){
$array2[] = $item->venue->name;
$array3[] = $item->venue->location->address;
$item_photo_urls = array();
foreach($item->photos->items as $photo){
$item_photo_urls[] = $photo->url;
}
$photos[] = $item_photo_urls;
}
Now you have a third array called photos , which contains all the photo urls.
现在你有了第三个名为photos的数组,其中包含所有的照片网址。
#3
0
Try this :
试试这个 :
$url = $item->photos->items[0]->url;
#1
2
$array1[0]->photos->items[0]->url
Remember - you access arrays with [index]
parenthesis, objects with ->
arrows.
记住 - 使用[index]括号访问数组,使用 - >箭头访问对象。
#2
1
Untested code:
$array2 = array();
$array3 = array();
$photos = array();
foreach($array1 as $item){
$array2[] = $item->venue->name;
$array3[] = $item->venue->location->address;
$item_photo_urls = array();
foreach($item->photos->items as $photo){
$item_photo_urls[] = $photo->url;
}
$photos[] = $item_photo_urls;
}
Now you have a third array called photos , which contains all the photo urls.
现在你有了第三个名为photos的数组,其中包含所有的照片网址。
#3
0
Try this :
试试这个 :
$url = $item->photos->items[0]->url;