3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [lat] => 40.7587979 [lng] => -73.9623427 [count] => 1 ) [1] => Array ( [lat] => 39.8587028 [lng] => -84.277025 [count] => 2 ) [2] => Array ( [lat] => 37.7647993 [lng] => -122.4629897 [count] => 2 ) [3] => Array ( [lat] => 33.5125302 [lng] => -117.6860507 [count] => 1 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
164.45 ms | 407 KiB | 5 Q