I am trying to build an array from entries in a MySQL database. I have connected to the database just fine, and I have a foreach loop which pulls the entries from the database based on the quantity of items like so:
$totalMarkers = count($results);
foreach($results as $result){
$gpsLats[] = $result->gpslat;
$gpsLongs[] = $result->gpslong;
}
I then need to take these entries and run them through a while loop to attempt to build my array:
$it = 0;
while ($it < $totalMarkers) {
$incr = $it++;
$myLatitudes = $gpsLats[$incr];
$myLongitudes = $gpsLongs[$incr];
$items = array($myLatitudes,$myLongitudes);
print_r($items);
}
The problem is that the output looks something like this:
Array ( [0] => 54.8607 [1] => -32.4135 )
Array ( [0] => 39.8460 [1] => -87.4166 )
Array ( [0] => 78.8403 [1] => -95.4156 )
Really what I need is for all the entries to be contained in one array statement. I have a good feeling that I am overcomplicating this, but I need a nudge in the right direction. Thanks for your time in looking into this.
$items[] = array($myLatitudes,$myLongitudes);2- moveprint_r($items);to outside the while loop$itemsarray in your firstforeachloop instead of running through everything twice?