Basic JSON Decode foreach loop not working php

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Basic JSON Decode foreach loop not working php



been going at this for quite some time and I'm puzzled as to why using foreach loops does not work but the other way I show does work.



My Code:


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://maps.googleapis.com/maps/api/geocode/json?address=1%20The%20Strand%20Wellard");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));

$response = curl_exec($ch);

$json = json_decode($response, true);

foreach ($json['results'] as $item) {
foreach ($item['geometry'] as $item2) {
foreach ($item2['location'] as $item3) {
echo $item3['lat'];
}
}
echo $item['geometry']['location']['lat'];
}

curl_close($ch);



JSON Data: https://pastebin.com/JU1wSpsD



Why doesn't echo $item3['lat']; work but echo $item['geometry']['location']['lat']; does work? If someone could help me understand why this is that would be great!


echo $item3['lat'];


echo $item['geometry']['location']['lat'];





add json data. to question.
– prasanna puttaswamy
13 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Future solutions