<?php $original_array = [ 0 => [ 'lat' => 40.7587979, 'lon' => -73.9623427 ], 1 => [ 'lat' => 39.8587028, 'lon' => -84.277025 ], 2 => [ 'lat' => 37.7647993, 'lon' => -122.4629897 ], 3 => [ 'lat' => 37.7647993, 'lon' => -122.4629897 ], 4 => [ 'lat' => 33.5125302, 'lon' => -117.6860507 ], 5 => [ 'lat' => 39.8587028, 'lon' => -84.277025 ], ]; // To hold the new array $out = []; // Outer loop over the result from array_count_values() foreach (array_count_values(array_map(function($l) { // Map function combines lat|lng return implode("|", $l); // The rest of the loop syntax... }, $original_array)) as $pair => $count) { // Split the counted array key back to individual lat,lng list($lat, $lng) = explode("|", $pair); // Put it all onto the output array $out[] = [ 'lat' => $lat, 'lng' => $lng, 'count' => $count ]; } print_r($out);
You have javascript disabled. You will not be able to edit any code.