I want to nest an array inside another array, my code will be similar to 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
)
Where the outer section (features) encapsulates many other arrays. I need to loop through variables pulled from a json file which I’ve already decoded — how would I loop through these sets of data? A foreach()?
Do you know the depth/no of children of the array? If you know does the depth always remains same? If answer to both of the question is yes then foreach should do the trick.
But If answer of any of those two question is no I would use a recursive function along with foreach, something like this.