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); } if(count($haystack == 1)){ return true;} else if(count($haystack) == 0) { return false;} } $x = range(0,999); BinSearch(82,$x);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OcTeP
function name:  (null)
number of ops:  10
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 999
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   21     5        INIT_FCALL                                               'binsearch'
          6        SEND_VAL                                                 82
          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
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
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: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
Branch analysis from position: 37
Branch analysis from position: 32
filename:       /in/OcTeP
function name:  BinSearch
number of ops:  42
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          
   16    32    >   IS_EQUAL                                         ~18     !1, 1
         33        COUNT                                            ~19     ~18
         34      > JMPZ                                                     ~19, ->37
         35    > > RETURN                                                   <true>
         36*       JMP                                                      ->41
         37    >   COUNT                                            ~20     !1
         38        IS_EQUAL                                                 ~20, 0
         39      > JMPZ                                                     ~21, ->41
         40    > > RETURN                                                   <false>
   18    41    > > RETURN                                                   null

End of function binsearch

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.64 ms | 1403 KiB | 18 Q