3v4l.org

run code in 300+ PHP versions simultaneously
<?php $c = [1,2,4,8,18,20,33,66,99]; function indexOfNumb(array $base, $x) { $leftI = 0; $rightI = count($base) - 1; do { $centerI = floor(($rightI + $leftI) / 2); if($base[$centerI] === $x) { return $centerI; } elseif($base[$centerI] > $x && $centerI !== $rightI) { $rightI = $centerI; } elseif($base[$centerI] < $x && $centerI !== $leftI) { $leftI = $centerI; } else { return ($x - $base[$leftI] > $base[$rightI] - $x) ? $rightI : $leftI; } } while(1); } var_dump(indexOfNumb($c, 65));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sULBB
function name:  (null)
number of ops:  9
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'indexofnumb'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 65
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function indexofnumb:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 6
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
Branch analysis from position: 25
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 22
filename:       /in/sULBB
function name:  indexOfNumb
number of ops:  45
compiled vars:  !0 = $base, !1 = $x, !2 = $leftI, !3 = $rightI, !4 = $centerI
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ASSIGN                                                   !2, 0
    7     3        COUNT                                            ~6      !0
          4        SUB                                              ~7      ~6, 1
          5        ASSIGN                                                   !3, ~7
   10     6    >   INIT_FCALL                                               'floor'
          7        ADD                                              ~9      !3, !2
          8        DIV                                              ~10     ~9, 2
          9        SEND_VAL                                                 ~10
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !4, $11
   12    12        FETCH_DIM_R                                      ~13     !0, !4
         13        IS_IDENTICAL                                             !1, ~13
         14      > JMPZ                                                     ~14, ->17
   13    15    > > RETURN                                                   !4
         16*       JMP                                                      ->43
   14    17    >   FETCH_DIM_R                                      ~15     !0, !4
         18        IS_SMALLER                                       ~16     !1, ~15
         19      > JMPZ_EX                                          ~16     ~16, ->22
         20    >   IS_NOT_IDENTICAL                                 ~17     !4, !3
         21        BOOL                                             ~16     ~17
         22    > > JMPZ                                                     ~16, ->25
   15    23    >   ASSIGN                                                   !3, !4
         24      > JMP                                                      ->43
   16    25    >   FETCH_DIM_R                                      ~19     !0, !4
         26        IS_SMALLER                                       ~20     ~19, !1
         27      > JMPZ_EX                                          ~20     ~20, ->30
         28    >   IS_NOT_IDENTICAL                                 ~21     !4, !2
         29        BOOL                                             ~20     ~21
         30    > > JMPZ                                                     ~20, ->33
   17    31    >   ASSIGN                                                   !2, !4
         32      > JMP                                                      ->43
   19    33    >   FETCH_DIM_R                                      ~23     !0, !2
         34        SUB                                              ~24     !1, ~23
         35        FETCH_DIM_R                                      ~25     !0, !3
         36        SUB                                              ~26     ~25, !1
         37        IS_SMALLER                                               ~26, ~24
         38      > JMPZ                                                     ~27, ->41
         39    >   QM_ASSIGN                                        ~28     !3
         40      > JMP                                                      ->42
         41    >   QM_ASSIGN                                        ~28     !2
         42    > > RETURN                                                   ~28
   21    43    > > JMPNZ                                                    1, ->6
   22    44    > > RETURN                                                   null

End of function indexofnumb

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.21 ms | 1394 KiB | 18 Q