3v4l.org

run code in 300+ PHP versions simultaneously
<?php function debug($arr){ echo '<pre>' ; print_r($arr); echo '</pre>'; } for($i=0; $i<5; $i++) { $arr[$i] = rand(0,10); } // $arr = Array // ( // 0 => 7, // 1 => 2, // 2 => 9, // 3 => 9, // 4 => 0, // ); // print_r($arr) . PHP_EOL; debug($arr) . PHP_EOL; $size_arr = sizeof($arr); // debug($size_arr) . PHP_EOL; $diff = array_sum($arr); for ($i=0; $i < $size_arr; $i++) { $a = $arr[$i]; //echo 'echo $i - ' . $i . PHP_EOL; //$index = [$diff => [$i,$j]]; for( $j=$i+1; $j < $size_arr; $j++) { $b = $arr[$j]; $newdiff = abs($a-$b); // echo $a . ' - ' . $b . ' = ' . $newdiff . '<br>'; //echo '------- $diff ----- ' . $diff . PHP_EOL; //echo '------- $newdiff --- ' . $newdiff . PHP_EOL; if ($newdiff < $diff) { $index = [$newdiff => [$i,$j]]; $diff = $newdiff; } elseif ($newdiff == $diff) { $newvalues = [$newdiff => [$i, $j]]; array_push($index, $newvalues); } } } debug($index);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 24
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 29
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 24
Branch analysis from position: 60
Branch analysis from position: 24
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 44
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 29
Branch analysis from position: 57
Branch analysis from position: 29
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 54
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 29
Branch analysis from position: 57
Branch analysis from position: 29
Branch analysis from position: 54
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 2
Branch analysis from position: 11
Branch analysis from position: 2
filename:       /in/3Fb7m
function name:  (null)
number of ops:  64
compiled vars:  !0 = $i, !1 = $arr, !2 = $size_arr, !3 = $diff, !4 = $a, !5 = $j, !6 = $b, !7 = $newdiff, !8 = $index, !9 = $newvalues
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->9
   10     2    >   INIT_FCALL                                               'rand'
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 10
          5        DO_ICALL                                         $12     
          6        ASSIGN_DIM                                               !1, !0
          7        OP_DATA                                                  $12
    9     8        PRE_INC                                                  !0
          9    >   IS_SMALLER                                               !0, 5
         10      > JMPNZ                                                    ~14, ->2
   23    11    >   INIT_FCALL                                               'debug'
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0  $15     
         14        CONCAT                                           ~16     $15, '%0A'
         15        FREE                                                     ~16
   24    16        COUNT                                            ~17     !1
         17        ASSIGN                                                   !2, ~17
   27    18        INIT_FCALL                                               'array_sum'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $19     
         21        ASSIGN                                                   !3, $19
   28    22        ASSIGN                                                   !0, 0
         23      > JMP                                                      ->58
   30    24    >   FETCH_DIM_R                                      ~22     !1, !0
         25        ASSIGN                                                   !4, ~22
   35    26        ADD                                              ~24     !0, 1
         27        ASSIGN                                                   !5, ~24
         28      > JMP                                                      ->55
   36    29    >   FETCH_DIM_R                                      ~26     !1, !5
         30        ASSIGN                                                   !6, ~26
   38    31        INIT_FCALL                                               'abs'
         32        SUB                                              ~28     !4, !6
         33        SEND_VAL                                                 ~28
         34        DO_ICALL                                         $29     
         35        ASSIGN                                                   !7, $29
   45    36        IS_SMALLER                                               !7, !3
         37      > JMPZ                                                     ~31, ->44
   46    38    >   INIT_ARRAY                                       ~32     !0
         39        ADD_ARRAY_ELEMENT                                ~32     !5
         40        INIT_ARRAY                                       ~33     ~32, !7
         41        ASSIGN                                                   !8, ~33
   48    42        ASSIGN                                                   !3, !7
         43      > JMP                                                      ->54
   50    44    >   IS_EQUAL                                                 !7, !3
         45      > JMPZ                                                     ~36, ->54
   51    46    >   INIT_ARRAY                                       ~37     !0
         47        ADD_ARRAY_ELEMENT                                ~37     !5
         48        INIT_ARRAY                                       ~38     ~37, !7
         49        ASSIGN                                                   !9, ~38
   52    50        INIT_FCALL                                               'array_push'
         51        SEND_REF                                                 !8
         52        SEND_VAR                                                 !9
         53        DO_ICALL                                                 
   35    54    >   PRE_INC                                                  !5
         55    >   IS_SMALLER                                               !5, !2
         56      > JMPNZ                                                    ~42, ->29
   28    57    >   PRE_INC                                                  !0
         58    >   IS_SMALLER                                               !0, !2
         59      > JMPNZ                                                    ~44, ->24
   57    60    >   INIT_FCALL                                               'debug'
         61        SEND_VAR                                                 !8
         62        DO_FCALL                                      0          
         63      > RETURN                                                   1

Function debug:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3Fb7m
function name:  debug
number of ops:  7
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ECHO                                                     '%3Cpre%3E'
    5     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
    6     5        ECHO                                                     '%3C%2Fpre%3E'
    7     6      > RETURN                                                   null

End of function debug

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
11.51 ms | 416 KiB | 7 Q