For php Data problems, consult experts! -Php Tutorial

Source: Internet
Author: User
For php Data problems, consult experts! Php array

There is an array like this:
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        ))

The latitude and longitude contain repeated data. to filter out duplicate data, you can obtain the number of identical latitude and longitude. The final array is as follows:


How can this be achieved?


Reply to discussion (solution)

$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] = & gt; 39.9289
[Longpolling] => 116.3883
[Count] => 1
)

[1] => Array
(
[Latitude] => 42
[Longpolling] => 43.5
[Count] => 1
)

[2] => Array
(
[Latitude] = & gt; 38.9122
[Longpolling] => 121.6022
[Count] => 3
)

[3] => Array
(
[Latitude] = & gt; 40.5525
[Longpolling] =>-74.2915
[Count] => 2
)

)

Paste the array output by var_export ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.