'Using PHP to access JSON objects
I have a geo.json file that I'm trying to pull certain data out of using PHP. I want to start just by echoing the "properties" object within the "features" array.
My geo.json file (only part of it as this is repeated for every country):
{
"type": "FeatureCollection",
"features":
[{"type":"Feature","properties":{"name":"Bahamas","iso_a2":"BS","iso_a3":"BHS","iso_n3":"044"},"geometry":{"type":"MultiPolygon","coordinates":[[[[-77.53466,23.75975],[-77.78,23.71],[-78.03405,24.28615],[-78.40848,24.57564],[-78.19087,25.2103],[-77.89,25.17],[-77.54,24.34],[-77.53466,23.75975]]],[[[-77.82,26.58],[-78.91,26.42],[-78.98,26.79],[-78.51,26.87],[-77.85,26.84],[-77.82,26.58]]],[[[-77,26.59],[-77.17255,25.87918],[-77.35641,26.00735],[-77.34,26.53],[-77.78802,26.92516],[-77.79,27.04],[-77,26.59]]]]}}
My PHP file:
<?php
$countryBordersJson = file_get_contents("countryBorders.geo.json");
$countryBordersJsonData = json_decode($countryBordersJson, true);
echo $countryBordersJsonData['features']['properties']['name'];
?>
I realise that the echo I've ended up with is probably totally wrong (I'm fairly new to PHP and JSON and this is part of my first solo project).
Can anyone help please?
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
