3v4l.org

run code in 300+ PHP versions simultaneously
<?php $points = [ [0, -1], [-2, 3], [4, 0], [3, 1], [5, 2], [0, 1], ]; $max_closest = []; foreach ($points as $i => list($ax, $ay)) { $min_dist = INF; $dists = []; foreach ($points as $j => list($bx, $by)) { if ($i == $j) { continue; } $dists[$j] = $sq_dist = ($bx - $ax) * ($bx - $ax) + ($by - $ay) * ($by - $ay); if ($sq_dist < $min_dist) { $min_dist = $sq_dist; } } // select closest points foreach (array_keys($dists, $min_dist, true) as $key) { print_r($points[$key]); // print point // keep track of points that were closest if (isset($max_closest[$key])) { ++$max_closest[$key]; } else { $max_closest[$key] = 1; } } } rsort($max_closest); foreach (array_keys($max_closest, $max_closest[0], true) as $key) { print_r($points[$key]); // print point }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 59
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 59
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 37
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 37
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 36
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 57
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 57
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 54
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 57
Branch analysis from position: 37
Branch analysis from position: 59
2 jumps found. (Code = 77) Position 1 = 70, Position 2 = 76
Branch analysis from position: 70
2 jumps found. (Code = 78) Position 1 = 71, Position 2 = 76
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 76
Branch analysis from position: 59
filename:       /in/2Z7cj
function name:  (null)
number of ops:  78
compiled vars:  !0 = $points, !1 = $max_closest, !2 = $ax, !3 = $ay, !4 = $i, !5 = $min_dist, !6 = $dists, !7 = $bx, !8 = $by, !9 = $j, !10 = $sq_dist, !11 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1        ASSIGN                                                   !1, <array>
   14     2      > FE_RESET_R                                       $14     !0, ->59
          3    > > FE_FETCH_R                                       ~20     $14, $15, ->59
          4    >   FETCH_LIST_R                                     $16     $15, 0
          5        ASSIGN                                                   !2, $16
          6        FETCH_LIST_R                                     $18     $15, 1
          7        ASSIGN                                                   !3, $18
          8        FREE                                                     $15
          9        ASSIGN                                                   !4, ~20
   15    10        ASSIGN                                                   !5, INF
   16    11        ASSIGN                                                   !6, <array>
   18    12      > FE_RESET_R                                       $24     !0, ->37
         13    > > FE_FETCH_R                                       ~30     $24, $25, ->37
         14    >   FETCH_LIST_R                                     $26     $25, 0
         15        ASSIGN                                                   !7, $26
         16        FETCH_LIST_R                                     $28     $25, 1
         17        ASSIGN                                                   !8, $28
         18        FREE                                                     $25
         19        ASSIGN                                                   !9, ~30
   19    20        IS_EQUAL                                                 !4, !9
         21      > JMPZ                                                     ~32, ->23
   20    22    > > JMP                                                      ->13
   22    23    >   SUB                                              ~34     !7, !2
         24        SUB                                              ~35     !7, !2
         25        MUL                                              ~36     ~34, ~35
         26        SUB                                              ~37     !8, !3
         27        SUB                                              ~38     !8, !3
         28        MUL                                              ~39     ~37, ~38
         29        ADD                                              ~40     ~36, ~39
         30        ASSIGN                                           ~41     !10, ~40
         31        ASSIGN_DIM                                               !6, !9
         32        OP_DATA                                                  ~41
   24    33        IS_SMALLER                                               !10, !5
         34      > JMPZ                                                     ~42, ->36
   25    35    >   ASSIGN                                                   !5, !10
   18    36    > > JMP                                                      ->13
         37    >   FE_FREE                                                  $24
   30    38        INIT_FCALL                                               'array_keys'
         39        SEND_VAR                                                 !6
         40        SEND_VAR                                                 !5
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $44     
         43      > FE_RESET_R                                       $45     $44, ->57
         44    > > FE_FETCH_R                                               $45, !11, ->57
   31    45    >   INIT_FCALL                                               'print_r'
         46        FETCH_DIM_R                                      ~46     !0, !11
         47        SEND_VAL                                                 ~46
         48        DO_ICALL                                                 
   34    49        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !11
         50      > JMPZ                                                     ~48, ->54
   35    51    >   FETCH_DIM_RW                                     $49     !1, !11
         52        PRE_INC                                                  $49
         53      > JMP                                                      ->56
   37    54    >   ASSIGN_DIM                                               !1, !11
         55        OP_DATA                                                  1
   30    56    > > JMP                                                      ->44
         57    >   FE_FREE                                                  $45
   14    58      > JMP                                                      ->3
         59    >   FE_FREE                                                  $14
   42    60        INIT_FCALL                                               'rsort'
         61        SEND_REF                                                 !1
         62        DO_ICALL                                                 
   44    63        INIT_FCALL                                               'array_keys'
         64        SEND_VAR                                                 !1
         65        FETCH_DIM_R                                      ~53     !1, 0
         66        SEND_VAL                                                 ~53
         67        SEND_VAL                                                 <true>
         68        DO_ICALL                                         $54     
         69      > FE_RESET_R                                       $55     $54, ->76
         70    > > FE_FETCH_R                                               $55, !11, ->76
   45    71    >   INIT_FCALL                                               'print_r'
         72        FETCH_DIM_R                                      ~56     !0, !11
         73        SEND_VAL                                                 ~56
         74        DO_ICALL                                                 
   44    75      > JMP                                                      ->70
         76    >   FE_FREE                                                  $55
   46    77      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.1 ms | 1404 KiB | 19 Q