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 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
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 ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
147.52 ms | 408 KiB | 5 Q