首页 > 后端开发 > php教程 > php数据问题,请教高手!

php数据问题,请教高手!

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-23 14:24:23
原创
1034 人浏览过

php 数组

有这样一个数组:
Array(    [0] => Array        (            [time] => 1382060855000            [day] => 2013-10-18            [latitude] => 39.9289            [longitude] => 116.3883        )    [1] => Array        (            [time] => 1382060855000            [day] => 2013-10-18            [latitude] => 42            [longitude] => 43.5        )    [2] => Array        (            [time] => 1382060855000            [day] => 2013-10-18            [latitude] => 38.9122            [longitude] => 121.6022        )    [3] => Array        (            [time] => 1382060855000            [day] => 2013-10-18            [latitude] => 40.5525            [longitude] => -74.2915        )    [4] => Array        (            [time] => 1382060855000            [day] => 2013-10-18            [latitude] => 40.5525            [longitude] => -74.2915        )    [5] => Array        (            [time] => 1382060855000            [day] => 2013-10-18            [latitude] => 38.9122            [longitude] => 121.6022        )    [6] => Array        (            [time] => 1382060855000            [day] => 2013-10-18            [latitude] => 38.9122            [longitude] => 121.6022        ))
登录后复制

里面的经纬度有重复的数据,想过滤掉重复数据,并且得到每一个相同经纬度的数量。最后得到的数组如下:


这个要怎么实现呢?


回复讨论(解决方案)

$ar = array (  0 =>   array (    'time' => '1382060855000',    'day' => '2013-10-18',    'latitude' => '39.9289',    'longitude' => '116.3883',  ),  1 =>   array (    'time' => '1382060855000',    'day' => '2013-10-18',    'latitude' => '42',    'longitude' => '43.5',  ),  2 =>   array (    'time' => '1382060855000',    'day' => '2013-10-18',    'latitude' => '38.9122',    'longitude' => '121.6022',  ),  3 =>   array (    'time' => '1382060855000',    'day' => '2013-10-18',    'latitude' => '40.5525',    'longitude' => '-74.2915',  ),  4 =>   array (    'time' => '1382060855000',    'day' => '2013-10-18',    'latitude' => '40.5525',    'longitude' => '-74.2915',  ),  5 =>   array (    'time' => '1382060855000',    'day' => '2013-10-18',    'latitude' => '38.9122',    'longitude' => '121.6022',  ),  6 =>   array (    'time' => '1382060855000',    'day' => '2013-10-18',    'latitude' => '38.9122',    'longitude' => '121.6022',  ),);$res = array();foreach($ar as $v) {  $k = $v['latitude'] . ',' . $v['longitude'];  if(isset($res[$k])) $res[$k]['count']++;  else $res[$k] = array('latitude' => $v['latitude'], 'longitude' => $v['longitude'], 'count' => 1);}print_r(array_values($res));
登录后复制

Array
(
    [0] => Array
        (
            [latitude] => 39.9289
            [longitude] => 116.3883
            [count] => 1
        )

    [1] => Array
        (
            [latitude] => 42
            [longitude] => 43.5
            [count] => 1
        )

    [2] => Array
        (
            [latitude] => 38.9122
            [longitude] => 121.6022
            [count] => 3
        )

    [3] => Array
        (
            [latitude] => 40.5525
            [longitude] => -74.2915
            [count] => 2
        )

)

贴出经var_export(); 输出后的数组出来

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
请教各位高手,关于 PHP取值问题
来自于 1970-01-01 08:00:00
0
0
0
请教一个mysql数据迸发问题
来自于 1970-01-01 08:00:00
0
0
0
请教一下同一个数据高迸发操作的问题
来自于 1970-01-01 08:00:00
0
0
0
请教高手,一个tp5多条件筛选 路由问题
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板