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 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 19
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 24
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 19
Branch analysis from position: 55
Branch analysis from position: 19
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 24
Branch analysis from position: 52
Branch analysis from position: 24
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 49
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 24
Branch analysis from position: 52
Branch analysis from position: 24
Branch analysis from position: 49
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/cVqus
function name:  (null)
number of ops:  59
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
   24    11    >   COUNT                                            ~15     !1
         12        ASSIGN                                                   !2, ~15
   27    13        INIT_FCALL                                               'array_sum'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $17     
         16        ASSIGN                                                   !3, $17
   28    17        ASSIGN                                                   !0, 0
         18      > JMP                                                      ->53
   30    19    >   FETCH_DIM_R                                      ~20     !1, !0
         20        ASSIGN                                                   !4, ~20
   35    21        ADD                                              ~22     !0, 1
         22        ASSIGN                                                   !5, ~22
         23      > JMP                                                      ->50
   36    24    >   FETCH_DIM_R                                      ~24     !1, !5
         25        ASSIGN                                                   !6, ~24
   38    26        INIT_FCALL                                               'abs'
         27        SUB                                              ~26     !4, !6
         28        SEND_VAL                                                 ~26
         29        DO_ICALL                                         $27     
         30        ASSIGN                                                   !7, $27
   45    31        IS_SMALLER                                               !7, !3
         32      > JMPZ                                                     ~29, ->39
   46    33    >   INIT_ARRAY                                       ~30     !0
         34        ADD_ARRAY_ELEMENT                                ~30     !5
         35        INIT_ARRAY                                       ~31     ~30, !7
         36        ASSIGN                                                   !8, ~31
   48    37        ASSIGN                                                   !3, !7
         38      > JMP                                                      ->49
   50    39    >   IS_EQUAL                                                 !7, !3
         40      > JMPZ                                                     ~34, ->49
   51    41    >   INIT_ARRAY                                       ~35     !0
         42        ADD_ARRAY_ELEMENT                                ~35     !5
         43        INIT_ARRAY                                       ~36     ~35, !7
         44        ASSIGN                                                   !9, ~36
   52    45        INIT_FCALL                                               'array_push'
         46        SEND_REF                                                 !8
         47        SEND_VAR                                                 !9
         48        DO_ICALL                                                 
   35    49    >   PRE_INC                                                  !5
         50    >   IS_SMALLER                                               !5, !2
         51      > JMPNZ                                                    ~40, ->24
   28    52    >   PRE_INC                                                  !0
         53    >   IS_SMALLER                                               !0, !2
         54      > JMPNZ                                                    ~42, ->19
   57    55    >   INIT_FCALL                                               'debug'
         56        SEND_VAR                                                 !8
         57        DO_FCALL                                      0          
         58      > RETURN                                                   1

Function debug:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cVqus
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:
150.77 ms | 1403 KiB | 24 Q