Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json decode with root property [closed]

Tags:

json

php

I cant seem to figure out, or find any information to help me solve what should be a simple problem.. I have some php code, it using curl get request to talk to an api, and the responce im getting from the api is

{"styleHolder":[{"id":100000929,"makeId":200005143,"year":2001,"makeName":"Ford","makeNiceName":"ford","modelId":"Ford_F_150","ect.......

What I need is to take the id, and turn it into a php variable..

I know how to use something like:

$myArray = json_decode($resp);
$id = $myArray->id;
echo $id;

but because the responce has styleHolder as a root property, I cant seem to figure out how to parce out id.. Any help would be great!

like image 668
user1789437 Avatar asked Jul 07 '26 07:07

user1789437


1 Answers

styleHolder is an array, so you need to first access the array element, then it's id property.

$myArray = json_decode($resp);
$id = $myArray->styleHolder[0]->id;
echo $id;
like image 131
Rocket Hazmat Avatar answered Jul 09 '26 22:07

Rocket Hazmat