我在PHP中有这个数组我想在每个索引上存储纬度和经度两个值,所以我如何存储这两个值,我需要它来进一步计算
Array
(
[0] => Array
(
[latitude] => 3.100
[longitude] => 3.210
)
[1] => Array
(
[latitude] => 33.54589450686039
[longitude] => 73.01294803619385
)
[2] => Array
(
[latitude] => 33.54589450686039
[longitude] => 73.01294803619385
)
[3] => Array
(
[latitude] => 33.577769773578304
[longitude] => 73.03532972931862
)
[4] => Array
(
[latitude] => 33.6844
[longitude] => 73.0479
)
)
发布于 2019-03-27 10:43:35
<?php
$long = [];
$lat = [];
$geoCoordinates = [
[
'latitude' => 3.100,
'longitude' => 3.210
],
[
'latitude' => 33.54589450686039,
'longitude' => 73.01294803619385
]
];
$i = 0;
foreach ($geoCoordinates as $coordinate) {
$lat = $coordinate['latitude'];
$long = $coordinate['longitude'];
echo "\n------ coordinate no $i -------\n";
Echo '$lat = ' . $lat . '<br>' . PHP_EOL;
Echo '$long = ' . $long . '<br>' . PHP_EOL;
// you can use them here to insert into Database etc.
$i++;
}
给你-输出:
------ coordinate no 0 -------
$lat = 3.1
$long = 3.21
------ coordinate no 1 -------
$lat = 33.54589450686
$long = 73.012948036194
https://stackoverflow.com/questions/-100006515
复制相似问题