首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何从多维数组[保持]动态存储变量中的值

如何从多维数组[保持]动态存储变量中的值
EN

Stack Overflow用户
提问于 2019-03-27 01:01:47
回答 1查看 0关注 0票数 0

我在PHP中有这个数组我想在每个索引上存储纬度和经度两个值,所以我如何存储这两个值,我需要它来进一步计算

代码语言:javascript
复制
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
        )
)
EN

回答 1

Stack Overflow用户

发布于 2019-03-27 10:43:35

代码语言:txt
复制
<?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++;
}    

给你-输出:

代码语言:txt
复制
------ coordinate no 0 -------
$lat = 3.1
$long = 3.21

------ coordinate no 1 -------
$lat = 33.54589450686
$long = 73.012948036194
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档