简体   繁体   English

json_decode访问具有多个相同键的嵌套数组

[英]json_decode access nested array with multiple identical keys

I am trying to access a specific value from an array, but have difficulties fetching it. 我正在尝试从数组访问特定值,但在获取它时遇到困难。 More specifically it is the value DealerCarExtended-->ImageIds-->ImageId-->Id, but my problem is that ImageIds is an array with multiple ImageId's. 更具体地说,它是值DealerCarExtended-> ImageIds-> ImageId-> Id,但是我的问题是ImageIds是具有多个ImageId的数组。 I use son_decode, but the code below obviously doesn't work. 我使用son_decode,但是下面的代码显然不起作用。

$response = file_get_contents( 'http://api.autoit.dk/car/GetCarsExtended/391B093F-BB4A-45AA-BEFF-7B33842401EA' );

$myArray = json_decode($response,true);

$myArray = $myArray[0];

echo $myArray['ImageIds']['ImageId']['Id'];

I'm sure that this is trivial for most of you guys but i'm a newbie in this :-) 我敢肯定,对于大多数人来说这是微不足道的,但是我是这个领域的新手:-)

A working example : 一个工作示例:

$response = file_get_contents( 'http://api.autoit.dk/car/GetCarsExtended/391B093F-BB4A-45AA-BEFF-7B33842401EA' );

$myArray = json_decode($response,true);

$myArray = $myArray[0];

# fetching second array item :
echo $myArray['ImageIds'][1]['Id']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM