The following code is building the proper structure of array that I want, but it's only doing it for one result even though the MYSQL result is about 65 items.
I need the 'type' and 'features' levels to be static, and then start the loop within the features level (so every mysql result would build an item in within the features level)
The following is only loading the last result from the query:
$db->setQuery($query);
$item=$db->loadObjectList();
echo $db->getErrorMsg();
//dump($item);
$stores = [
'type' => 'FeatureCollection',
'features' => [
foreach ($item as $i) {
[
'type' => 'Feature',
'geometry' => [
'type' => 'Point',
'coordinates' => [
$i->lat,
$i->lng
]
],
'properties' => [
'storeImage' => $i->logo, // you need to convert this into an actual URL
'storeName' => $i->name,
'phoneFormatted' => $i->phone, // this needs formatting aswell
'address' => $i->address,
'city' => $i->city,
'country' => $i->country,
'postalCode' => $i->zip,
'state' => $i->state
]
]
}
]
];
How can I properly loop the mysql query to build my array in the correct way?
foreachinside an array element. You could usearray_map();in the middle of the array was wrong