3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [20, 1, 5, 10, 7, 16]; $keys = array_keys($arr); $nearest = max($arr) - min($arr) + 1; $result = []; for($key = 0, $length = count($arr); $key < $length; $key++){ for($innerKey = $key + 1; $innerKey < $length; $innerKey++){ if( ($diff = abs($arr[$keys[$key]] - $arr[$keys[$innerKey]])) < $nearest){ $result = [$arr[$keys[$key]], $arr[$keys[$innerKey]]]; $nearest = $diff; } } } print_r($result); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 19
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 22
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 19
Branch analysis from position: 47
Branch analysis from position: 19
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 41
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 22
Branch analysis from position: 44
Branch analysis from position: 22
Branch analysis from position: 41
filename:       /in/jA24X
function name:  (null)
number of ops:  51
compiled vars:  !0 = $arr, !1 = $keys, !2 = $nearest, !3 = $result, !4 = $key, !5 = $length, !6 = $innerKey, !7 = $diff
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    5     1        INIT_FCALL                                                   'array_keys'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $9      
          4        ASSIGN                                                       !1, $9
    6     5        INIT_FCALL                                                   'max'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                             $11     
          8        INIT_FCALL                                                   'min'
          9        SEND_VAR                                                     !0
         10        DO_ICALL                                             $12     
         11        SUB                                                  ~13     $11, $12
         12        ADD                                                  ~14     ~13, 1
         13        ASSIGN                                                       !2, ~14
    7    14        ASSIGN                                                       !3, <array>
    9    15        ASSIGN                                                       !4, 0
         16        COUNT                                                ~18     !0
         17        ASSIGN                                                       !5, ~18
         18      > JMP                                                          ->45
   11    19    >   ADD                                                  ~20     !4, 1
         20        ASSIGN                                                       !6, ~20
         21      > JMP                                                          ->42
   13    22    >   INIT_FCALL                                                   'abs'
         23        FETCH_DIM_R                                          ~22     !1, !4
         24        FETCH_DIM_R                                          ~23     !0, ~22
         25        FETCH_DIM_R                                          ~24     !1, !6
         26        FETCH_DIM_R                                          ~25     !0, ~24
         27        SUB                                                  ~26     ~23, ~25
         28        SEND_VAL                                                     ~26
         29        DO_ICALL                                             $27     
         30        ASSIGN                                               ~28     !7, $27
         31        IS_SMALLER                                                   ~28, !2
         32      > JMPZ                                                         ~29, ->41
   14    33    >   FETCH_DIM_R                                          ~30     !1, !4
         34        FETCH_DIM_R                                          ~31     !0, ~30
         35        INIT_ARRAY                                           ~32     ~31
         36        FETCH_DIM_R                                          ~33     !1, !6
         37        FETCH_DIM_R                                          ~34     !0, ~33
         38        ADD_ARRAY_ELEMENT                                    ~32     ~34
         39        ASSIGN                                                       !3, ~32
   15    40        ASSIGN                                                       !2, !7
   11    41    >   PRE_INC                                                      !6
         42    >   IS_SMALLER                                                   !6, !5
         43      > JMPNZ                                                        ~38, ->22
    9    44    >   PRE_INC                                                      !4
         45    >   IS_SMALLER                                                   !4, !5
         46      > JMPNZ                                                        ~40, ->19
   23    47    >   INIT_FCALL                                                   'print_r'
         48        SEND_VAR                                                     !3
         49        DO_ICALL                                                     
   25    50      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
173.09 ms | 2119 KiB | 18 Q