I'm querying the instagram api to return json with this code:
$instagramClientID = '9110e8c268384cb79901a96e3a16f588';
$api = 'https://api.instagram.com/v1/tags/zipcar/media/recent?client_id='.$instagramClientID; //api request (edit this to reflect tags)
$response = get_curl($api); //change request path to pull different photos
So I want to decode the json
if($response){
// Decode the response and build an array
foreach(json_decode($response)->data as $item){
...
So now I want to reformat the contents of said array into a particular json format (geojson) the code would be roughly this:
array(
'type' => 'FeatureCollection',
'features' => array(
array(
'type' => 'Feature',
'geometry' => array(
'coordinates' => array(-94.34885, 39.35757),
'type' => 'Point'
), // geometry
'properties' => array(
// latitude, longitude, id etc.
) // properties
), // end of first feature
array( ... ), // etc.
) // features
)
And then use json_encode
to return it all into a nice json file to cache on the server.
My question...is how to I use the code above to loop through the json? The outer structure of the array/json is static but the interior needs to change.