3v4l.org

run code in 300+ PHP versions simultaneously
<?php $A = [-9, -2, 1, 5, 9]; $X = 5; function solution(&$A, $X) { $N = sizeof($A); if ($N == 0) { return -1; } $l = 0; $r = $N - 1; $i = 0; while ($l < $r && $l !== $A[$m] ) { $m = (int)(($l + $r) / 2); if ($A[$m] > $X) { echo 1; $r = $m - 1; } else { $l = $m; } $i++; echo $l , $r, PHP_EOL; if ($i >= 10 ) exit; } if ($A[$l] == $X) { return $l; } else return -1; } var_dump(solution($A, $X));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2b3Li
function name:  (null)
number of ops:  10
compiled vars:  !0 = $A, !1 = $X
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 5
   32     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'solution'
          4        SEND_REF                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function solution:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 12
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 42
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
Branch analysis from position: 31
Branch analysis from position: 36
filename:       /in/2b3Li
function name:  solution
number of ops:  44
compiled vars:  !0 = $A, !1 = $X, !2 = $N, !3 = $l, !4 = $r, !5 = $i, !6 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        COUNT                                            ~7      !0
          3        ASSIGN                                                   !2, ~7
    8     4        IS_EQUAL                                                 !2, 0
          5      > JMPZ                                                     ~9, ->7
    9     6    > > RETURN                                                   -1
   11     7    >   ASSIGN                                                   !3, 0
   12     8        SUB                                              ~11     !2, 1
          9        ASSIGN                                                   !4, ~11
   13    10        ASSIGN                                                   !5, 0
   14    11      > JMP                                                      ->31
   15    12    >   ADD                                              ~14     !3, !4
         13        DIV                                              ~15     ~14, 2
         14        CAST                                          4  ~16     ~15
         15        ASSIGN                                                   !6, ~16
   16    16        FETCH_DIM_R                                      ~18     !0, !6
         17        IS_SMALLER                                               !1, ~18
         18      > JMPZ                                                     ~19, ->23
   17    19    >   ECHO                                                     1
   18    20        SUB                                              ~20     !6, 1
         21        ASSIGN                                                   !4, ~20
         22      > JMP                                                      ->24
   20    23    >   ASSIGN                                                   !3, !6
   22    24    >   PRE_INC                                                  !5
   23    25        ECHO                                                     !3
         26        ECHO                                                     !4
         27        ECHO                                                     '%0A'
   24    28        IS_SMALLER_OR_EQUAL                                      10, !5
         29      > JMPZ                                                     ~24, ->31
         30    > > EXIT                                                     
   14    31    >   IS_SMALLER                                       ~25     !3, !4
         32      > JMPZ_EX                                          ~25     ~25, ->36
         33    >   FETCH_DIM_R                                      ~26     !0, !6
         34        IS_NOT_IDENTICAL                                 ~27     !3, ~26
         35        BOOL                                             ~25     ~27
         36    > > JMPNZ                                                    ~25, ->12
   26    37    >   FETCH_DIM_R                                      ~28     !0, !3
         38        IS_EQUAL                                                 !1, ~28
         39      > JMPZ                                                     ~29, ->42
   27    40    > > RETURN                                                   !3
         41*       JMP                                                      ->43
   29    42    > > RETURN                                                   -1
   30    43*     > RETURN                                                   null

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.1 ms | 1403 KiB | 16 Q