php数据问题,请教高手!
有这样一个数组:
$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));