I need to make an array of locations arrays, it must look like this
$relevanceKeys = array(
\'locations\' => array(
array(
\'longitud
Since you're only needing to push elements to the array, you can simply use the []
struct as follows:
while ($row = $result->fetch_object())
{
$relevanceKeys['locations'][] = array (
'longitude' => $row->longitude,
'latitude' => $row->latitude
);
}
Just append the array like this:
$relevanceKeys['locations'][] = $array;
//^^ See here
You don't have to merge them all the time!
Also I think you want to change this:
$array = array(
array (
'longitude' => $row->longitude,
'latitude' => $row->latitude
)
);
to this to get your expected structure:
$array = array(
'longitude' => $row->longitude,
'latitude' => $row->latitude
);
For more information about array see the manual: http://php.net/manual/en/language.types.array.php