Hi all
Having a small issue trying to figure out the basics to loop through an object and display some data.
//The $ouput variable holds the JSON below
$output = json_decode($outputDetails);
JSON for viewing:
{
"results": [
{
"formatted_address": "Address Name 1, United Kingdom",
"geometry": {
"location": {
"lat": 00.0000000,
"lng": -0.0000000
},
},
"name": "Item Name 1",
"types": [
"type1",
"type2",
"type3"
],
"user_ratings_total": 0000
},
{
"formatted_address": "Address Name 2, United Kingdom",
"geometry": {
"location": {
"lat": 00.0000000,
"lng": -0.0000000
},
},
"name": "Item Name 2",
"types": [
"type1",
"type2",
"type3"
],
"user_ratings_total": 0000
},
{
"formatted_address": "Address Name 3, United Kingdom",
"geometry": {
"location": {
"lat": 00.0000000,
"lng": -0.0000000
},
},
"name": "Item Name 3",
"types": [
"type1",
"type2",
"type3"
],
"user_ratings_total": 0000
}
]
}
Now when I try and display and loop through this data I keep getting
Notice : Trying to get property of non-object in…
What am I doing wrong?
foreach($output as $item){
echo $item->results->formatted_address;
echo "<br>";
echo $item->results->name;
}
Thanks
Barry