3v4l.org

run code in 500+ PHP versions simultaneously
<?php $numbers = array(1105,2140,3170,1000,1500,1501); $start = 1000; $end = 1500; $start_index = -1; sort($numbers); $low = 0; $high = count($numbers) - 1; while($low <= $high){ $mid = intval(($low + $high) / 2); if($numbers[$mid] > $end){ $high = $mid - 1; }else if($numbers[$mid] < $start){ $low = $mid + 1; }else{ $start_index = $mid; $high = $mid - 1; } } $result = []; for($i = $start_index; $i < count($numbers); ++$i){ if($numbers[$i] > $end) break; $result[] = $numbers[$i]; } print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 36
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 40
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 36
Branch analysis from position: 47
Branch analysis from position: 36
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
Branch analysis from position: 12
filename:       /in/WcgXv
function name:  (null)
number of ops:  51
compiled vars:  !0 = $numbers, !1 = $start, !2 = $end, !3 = $start_index, !4 = $low, !5 = $high, !6 = $mid, !7 = $result, !8 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    5     1        ASSIGN                                                       !1, 1000
    6     2        ASSIGN                                                       !2, 1500
    7     3        ASSIGN                                                       !3, -1
    9     4        INIT_FCALL                                                   'sort'
          5        SEND_REF                                                     !0
          6        DO_ICALL                                                     
   11     7        ASSIGN                                                       !4, 0
          8        COUNT                                                ~15     !0
          9        SUB                                                  ~16     ~15, 1
         10        ASSIGN                                                       !5, ~16
   13    11      > JMP                                                          ->31
   14    12    >   ADD                                                  ~18     !4, !5
         13        DIV                                                  ~19     ~18, 2
         14        CAST                                              4  ~20     ~19
         15        ASSIGN                                                       !6, ~20
   15    16        FETCH_DIM_R                                          ~22     !0, !6
         17        IS_SMALLER                                                   !2, ~22
         18      > JMPZ                                                         ~23, ->22
   16    19    >   SUB                                                  ~24     !6, 1
         20        ASSIGN                                                       !5, ~24
   15    21      > JMP                                                          ->31
   17    22    >   FETCH_DIM_R                                          ~26     !0, !6
         23        IS_SMALLER                                                   ~26, !1
         24      > JMPZ                                                         ~27, ->28
   18    25    >   ADD                                                  ~28     !6, 1
         26        ASSIGN                                                       !4, ~28
   17    27      > JMP                                                          ->31
   20    28    >   ASSIGN                                                       !3, !6
   21    29        SUB                                                  ~31     !6, 1
         30        ASSIGN                                                       !5, ~31
   13    31    >   IS_SMALLER_OR_EQUAL                                          !4, !5
         32      > JMPNZ                                                        ~33, ->12
   25    33    >   ASSIGN                                                       !7, <array>
   26    34        ASSIGN                                                       !8, !3
         35      > JMP                                                          ->44
   27    36    >   FETCH_DIM_R                                          ~36     !0, !8
         37        IS_SMALLER                                                   !2, ~36
         38      > JMPZ                                                         ~37, ->40
         39    > > JMP                                                          ->47
   28    40    >   FETCH_DIM_R                                          ~39     !0, !8
         41        ASSIGN_DIM                                                   !7
         42        OP_DATA                                                      ~39
   26    43        PRE_INC                                                      !8
         44    >   COUNT                                                ~41     !0
         45        IS_SMALLER                                                   !8, ~41
         46      > JMPNZ                                                        ~42, ->36
   31    47    >   INIT_FCALL                                                   'print_r'
         48        SEND_VAR                                                     !7
         49        DO_ICALL                                                     
         50      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.02 ms | 2134 KiB | 15 Q