I know similar sort of questions been asked before. But reason I'm asking is because I have tried many of those solution provided here in those questions, but nothing seemed to work for me. :( Let's say I have tried these questions: 1 2 3
Background
I'm calling to a RESTAPI and get data in json format.
$apiResult = connect_to_api($link); // function works fine
echo '<pre>';
echo print_r(json_decode($apiResult));
echo '</pre>';
when I print, I get following result:
stdClass Object
(
[id] => 91
[name_1] => city name
[name_2] => area name
[name_3] => municipality
[web] => www.example.com
)
Problem Scope
When I try to access only value of id
it says trying to get non-object property. Like for example I tried
echo $apiResult->id;
foreach($apiResult as $result){
echo $result->id;
}
Nothing did really work. Don't know where am I going wrong. Any help or suggestion is appreciated. Thanks in advance.