Using an application's API, I'm able to retrieve data as a JSON and put it in an array.
$json = file_get_contents($url);
$obj = json_decode($json);
print_r($obj);
When I print the array, I see:
stdClass Object(
[metadataList] = > stdClass Object(
[metadata] = > Array(
[0] = > stdClass Object([metadataName] = > category [metadataValue] = > RECIPES)
[1] = > stdClass Object([metadataName] = > title [metadataValue] = > Easy Sugar Cookies)
)
)
)
I need to set a variable equal to the title metadata value ("Easy Sugar Cookies"), but I'm having some trouble.
Here's where I am so far, but I'm not having any luck figuring out how to specify the specific metadataValue key, since there is more than one in the array.
$title = array_search('description',($obj->{'metadataList'}->{'metadata'}));
array_searchwon't help you because that string is in an Object.$obj->metadataList->metadata[1]->metadataValue(direct) or (expensive)foreach($obj->metadataList->metadata as $meta) { if($meta->metadatavalue == ... }