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);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 28
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 28
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/RT6m6
function name:  (null)
number of ops:  33
compiled vars:  !0 = $original_array, !1 = $out, !2 = $count, !3 = $pair, !4 = $lat, !5 = $lng
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   31     1        ASSIGN                                                   !1, <array>
   34     2        INIT_FCALL                                               'array_count_values'
          3        INIT_FCALL                                               'array_map'
          4        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
   38     5        SEND_VAL                                                 ~8
          6        SEND_VAR                                                 !0
   34     7        DO_ICALL                                         $9      
   38     8        SEND_VAR                                                 $9
   34     9        DO_ICALL                                         $10     
   38    10      > FE_RESET_R                                       $11     $10, ->28
         11    > > FE_FETCH_R                                       ~12     $11, !2, ->28
         12    >   ASSIGN                                                   !3, ~12
   41    13        INIT_FCALL                                               'explode'
         14        SEND_VAL                                                 '%7C'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $14     
         17        FETCH_LIST_R                                     $15     $14, 0
         18        ASSIGN                                                   !4, $15
         19        FETCH_LIST_R                                     $17     $14, 1
         20        ASSIGN                                                   !5, $17
         21        FREE                                                     $14
   45    22        INIT_ARRAY                                       ~20     !4, 'lat'
   46    23        ADD_ARRAY_ELEMENT                                ~20     !5, 'lng'
   47    24        ADD_ARRAY_ELEMENT                                ~20     !2, 'count'
   44    25        ASSIGN_DIM                                               !1
   47    26        OP_DATA                                                  ~20
   34    27      > JMP                                                      ->11
         28    >   FE_FREE                                                  $11
   51    29        INIT_FCALL                                               'print_r'
         30        SEND_VAR                                                 !1
         31        DO_ICALL                                                 
         32      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RT6m6
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $l
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 '%7C'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   38     6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.59 ms | 1020 KiB | 18 Q