需要从嵌套数组对象中分配变量(Need to assign variables from nested array object)

编程入门 行业动态 更新时间:2024-10-24 19:18:16
需要从嵌套数组对象中分配变量(Need to assign variables from nested array object)

我确信我在这里遗漏了一些简单的东西,但是在从包含多个嵌套数组的对象中获取值时遇到了麻烦。

这是分配的对象:

$obj = json_decode($uri); // Convert JSON

这是来自此对象的print_r:

Array ( [0] => stdClass Object ( [total] => 1 [results] => Array ( [0] => stdClass Object ( [coordinates] => Array ( [0] => -88.359306 [1] => 41.685747 ) [country_id] => US [state_id] => IL [address_locality] => Oswego [address_text] => 201Washington St [street_number] => 201 [street_name] => Washington St [confidence] => 0.71 [county_id] => 17093 [_type] => geo.place [geo_geometry_type] => Point ) ) ) )

我无法获得county_id,坐标等的值...

我试图使用像$ obj-> results [0] - > coordinates [0] ....但这没有用

I am sure I am missing something simple here but am having trouble grabbing values from an object that contains several nested arrays.

Here is the object being assigned:

$obj = json_decode($uri); // Convert JSON

Here is the print_r from this object:

Array ( [0] => stdClass Object ( [total] => 1 [results] => Array ( [0] => stdClass Object ( [coordinates] => Array ( [0] => -88.359306 [1] => 41.685747 ) [country_id] => US [state_id] => IL [address_locality] => Oswego [address_text] => 201Washington St [street_number] => 201 [street_name] => Washington St [confidence] => 0.71 [county_id] => 17093 [_type] => geo.place [geo_geometry_type] => Point ) ) ) )

I am having trouble getting at the values for county_id, coordinates, etc...

I was trying to use something like $obj->results[0]->coordinates[0].... but this didnt work

最满意答案

你只是在$ obj之后错过了[0]吗?

$obj[0]->results[0]->coordinates[0]

Are you just missing the [0] after $obj?

$obj[0]->results[0]->coordinates[0]

更多推荐

本文发布于:2023-07-31 02:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   数组   变量   分配   对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!