I know this is a simple concept (albeit one I struggle with) but I have some latitude and longitude data. It is read from a .data file (not as a .db, not my choice) and here is what I have so far:
$current_data = file("/my_data_file.data");
$latest_data = array();
foreach ($current_data as $entry)
{
$latest_data[] = $entry;
}
$latest_data = preg_replace("!\r?\n!", "", $latest_data);
echo json_encode($latest_data);
This outputs the data like so (didn't paste all of it here to save your eyes from bleeding):
["-118.510 33.896 ","-120.762 32.826 ","-122.959 31.716 ","-125.104 30.570 ","-127.198 29.389 ","-129.243 28.175 ","-131.243 26.931 ","-133.198 25.660 ","-135.112 24.362 ","-136.988 23.041 "]
So it's one giant array, each lat/long pair separated by a comma and each pair within quotations.
I've googled this and there is a ton of information on php arrays and key/values, but what's the right way to do it? I find myself making this much more complicated than it needs to be.
Assuming in the foreach loop it'll be something like
$latest_data[] = array('latitude' => $entry[the_lat_number], 'longitude' => $entry[the_long_number]);
Any input on the matter is appreciated.
Update: example of the data viewed in VIM (It doesn't visually appear there IS a whitespacing issue, but based on using explode, there does seem to be).

$latest_data[] = array('latitude' => $entry[the_lat_number], 'longitude' => $entry[the_long_number]);not work?explodewas a decent approach but with the inconsistent whitespace I'm not too sure if that is best.