3v4l.org

run code in 500+ PHP versions simultaneously
<?php // arrB to not get changes reflected once we sort $arrB = $array = [4, 1, 5, 52, 75, 52, 24]; function findMinDiff($arr) { $n = count($arr); // Initialize difference // as infinite $diff = PHP_INT_MAX; // Find the min diff by comparing // difference of all possible // pairs in given array $two_values = []; for ($i = 0; $i < $n - 1; $i++) { for ($j = $i + 1; $j < $n; $j++) { if (abs($arr[$i] - $arr[$j]) < $diff) { $diff = abs($arr[$i] - $arr[$j]); $two_values['values'] = [$arr[$i], $arr[$j]]; $two_values['keys'] = [$i, $j]; $two_values['diff'] = $diff; } } } // Return min diff return $two_values; } print_r(findMinDiff($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7oXk9
function name:  (null)
number of ops:  9
compiled vars:  !0 = $arrB, !1 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                               ~2      !1, <array>
          1        ASSIGN                                                       !0, ~2
   28     2        INIT_FCALL                                                   'print_r'
          3        INIT_FCALL                                                   'findmindiff'
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0  $4      
          6        SEND_VAR                                                     $4
          7        DO_ICALL                                                     
          8      > RETURN                                                       1

Function findmindiff:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 7
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 10
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 7
Branch analysis from position: 44
Branch analysis from position: 7
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 37
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 10
Branch analysis from position: 40
Branch analysis from position: 10
Branch analysis from position: 37
filename:       /in/7oXk9
function name:  findMinDiff
number of ops:  46
compiled vars:  !0 = $arr, !1 = $n, !2 = $diff, !3 = $two_values, !4 = $i, !5 = $j
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
    6     1        COUNT                                                ~6      !0
          2        ASSIGN                                                       !1, ~6
    9     3        ASSIGN                                                       !2, 9223372036854775807
   13     4        ASSIGN                                                       !3, <array>
   14     5        ASSIGN                                                       !4, 0
          6      > JMP                                                          ->41
   15     7    >   ADD                                                  ~11     !4, 1
          8        ASSIGN                                                       !5, ~11
          9      > JMP                                                          ->38
   16    10    >   INIT_FCALL                                                   'abs'
         11        FETCH_DIM_R                                          ~13     !0, !4
         12        FETCH_DIM_R                                          ~14     !0, !5
         13        SUB                                                  ~15     ~13, ~14
         14        SEND_VAL                                                     ~15
         15        DO_ICALL                                             $16     
         16        IS_SMALLER                                                   $16, !2
         17      > JMPZ                                                         ~17, ->37
   17    18    >   INIT_FCALL                                                   'abs'
         19        FETCH_DIM_R                                          ~18     !0, !4
         20        FETCH_DIM_R                                          ~19     !0, !5
         21        SUB                                                  ~20     ~18, ~19
         22        SEND_VAL                                                     ~20
         23        DO_ICALL                                             $21     
         24        ASSIGN                                                       !2, $21
   18    25        FETCH_DIM_R                                          ~24     !0, !4
         26        INIT_ARRAY                                           ~25     ~24
         27        FETCH_DIM_R                                          ~26     !0, !5
         28        ADD_ARRAY_ELEMENT                                    ~25     ~26
         29        ASSIGN_DIM                                                   !3, 'values'
         30        OP_DATA                                                      ~25
   19    31        INIT_ARRAY                                           ~28     !4
         32        ADD_ARRAY_ELEMENT                                    ~28     !5
         33        ASSIGN_DIM                                                   !3, 'keys'
         34        OP_DATA                                                      ~28
   20    35        ASSIGN_DIM                                                   !3, 'diff'
         36        OP_DATA                                                      !2
   15    37    >   PRE_INC                                                      !5
         38    >   IS_SMALLER                                                   !5, !1
         39      > JMPNZ                                                        ~31, ->10
   14    40    >   PRE_INC                                                      !4
         41    >   SUB                                                  ~33     !1, 1
         42        IS_SMALLER                                                   !4, ~33
         43      > JMPNZ                                                        ~34, ->7
   26    44    > > RETURN                                                       !3
   27    45*     > RETURN                                                       null

End of function findmindiff

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.24 ms | 2094 KiB | 16 Q