3v4l.org

run code in 300+ PHP versions simultaneously
<?php function BinSearch($needle, $haystack){ $midpoint = count($haystack) / 2; $lower_half = array_slice($haystack, 0, $midpoint); $upper_half = array_slice($haystack, -$midpoint, count($haystack)); if($needle < $midpoint){ BinSearch($needle, $lower_half); } else if($needle > $midpoint){ BinSearch($needle, $upper_half); } } $x = range(0,99); BinSearch(73,$x);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YBpp9
function name:  (null)
number of ops:  10
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 99
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   20     5        INIT_FCALL                                               'binsearch'
          6        SEND_VAL                                                 73
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0          
          9      > RETURN                                                   1

Function binsearch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/YBpp9
function name:  BinSearch
number of ops:  33
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $midpoint, !3 = $lower_half, !4 = $upper_half
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        COUNT                                            ~5      !1
          3        DIV                                              ~6      ~5, 2
          4        ASSIGN                                                   !2, ~6
    6     5        INIT_FCALL                                               'array_slice'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 0
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !3, $8
    7    11        INIT_FCALL                                               'array_slice'
         12        SEND_VAR                                                 !1
         13        MUL                                              ~10     !2, -1
         14        SEND_VAL                                                 ~10
         15        COUNT                                            ~11     !1
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !4, $12
    9    19        IS_SMALLER                                               !0, !2
         20      > JMPZ                                                     ~14, ->26
   10    21    >   INIT_FCALL_BY_NAME                                       'BinSearch'
         22        SEND_VAR_EX                                              !0
         23        SEND_VAR_EX                                              !3
         24        DO_FCALL                                      0          
         25      > JMP                                                      ->32
   12    26    >   IS_SMALLER                                               !2, !0
         27      > JMPZ                                                     ~16, ->32
   13    28    >   INIT_FCALL_BY_NAME                                       'BinSearch'
         29        SEND_VAR_EX                                              !0
         30        SEND_VAR_EX                                              !4
         31        DO_FCALL                                      0          
   17    32    > > RETURN                                                   null

End of function binsearch

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.82 ms | 1403 KiB | 18 Q