3v4l.org

run code in 500+ PHP versions simultaneously
<?php function array_search_range( mixed $needle, array $haystack, int $offset = 0, ?int $length = null, bool $strict = false, ): int|string|false { if ( $offset < 0 ) { $offset = count($haystack) + $offset; } if ( $length < 0 ) { $length = count($haystack) + $length - $offset; } $currentOffset = -1; foreach ( $haystack as $key => $value ) { $currentOffset++; if ( $currentOffset < $offset ) { continue; } if ( $length !== null && $currentOffset >= $offset + $length ) { break; } if ( ( $strict && $value === $needle ) || ( ! $strict && $value == $needle ) ) { return $key; } } return false; } $items = ['zero', 'one', 'two', 'target', 'four', 'target']; $key = array_search_range('target', $items, 2, 3, true); var_dump($key); // int(3) $items = ['zero', 'one', 'two', 'target', 'four', 'target']; $key = array_search_range('target', $items, 4, null, true); var_dump($key); // int(5) $items = ['zero', 'one', 'two', 'target', 'four', 'target']; $key = array_search_range('target', $items, 1, 2, true); var_dump($key); // bool(false) $items = ['zero', 'one', 'two', 'target', 'four', 'target']; $key = array_search_range('target', $items, 1, -3, true); var_dump($key); // bool(false)
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VAsXY
function name:  (null)
number of ops:  49
compiled vars:  !0 = $items, !1 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   ASSIGN                                                       !0, <array>
   38     1        INIT_FCALL                                                   'array_search_range'
          2        SEND_VAL                                                     'target'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     2
          5        SEND_VAL                                                     3
          6        SEND_VAL                                                     <true>
          7        DO_FCALL                                          0  $3      
          8        ASSIGN                                                       !1, $3
   39     9        INIT_FCALL                                                   'var_dump'
         10        SEND_VAR                                                     !1
         11        DO_ICALL                                                     
   41    12        ASSIGN                                                       !0, <array>
   42    13        INIT_FCALL                                                   'array_search_range'
         14        SEND_VAL                                                     'target'
         15        SEND_VAR                                                     !0
         16        SEND_VAL                                                     4
         17        SEND_VAL                                                     null
         18        SEND_VAL                                                     <true>
         19        DO_FCALL                                          0  $7      
         20        ASSIGN                                                       !1, $7
   43    21        INIT_FCALL                                                   'var_dump'
         22        SEND_VAR                                                     !1
         23        DO_ICALL                                                     
   45    24        ASSIGN                                                       !0, <array>
   46    25        INIT_FCALL                                                   'array_search_range'
         26        SEND_VAL                                                     'target'
         27        SEND_VAR                                                     !0
         28        SEND_VAL                                                     1
         29        SEND_VAL                                                     2
         30        SEND_VAL                                                     <true>
         31        DO_FCALL                                          0  $11     
         32        ASSIGN                                                       !1, $11
   47    33        INIT_FCALL                                                   'var_dump'
         34        SEND_VAR                                                     !1
         35        DO_ICALL                                                     
   49    36        ASSIGN                                                       !0, <array>
   50    37        INIT_FCALL                                                   'array_search_range'
         38        SEND_VAL                                                     'target'
         39        SEND_VAR                                                     !0
         40        SEND_VAL                                                     1
         41        SEND_VAL                                                     -3
         42        SEND_VAL                                                     <true>
         43        DO_FCALL                                          0  $15     
         44        ASSIGN                                                       !1, $15
   51    45        INIT_FCALL                                                   'var_dump'
         46        SEND_VAR                                                     !1
         47        DO_ICALL                                                     
         48      > RETURN                                                       1

Function array_search_range:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 45
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 45
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
2 jumps found. (Code = 47) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 39
Branch analysis from position: 40
Branch analysis from position: 34
Branch analysis from position: 29
Branch analysis from position: 45
Branch analysis from position: 45
Branch analysis from position: 16
Branch analysis from position: 10
filename:       /in/VAsXY
function name:  array_search_range
number of ops:  49
compiled vars:  !0 = $needle, !1 = $haystack, !2 = $offset, !3 = $length, !4 = $strict, !5 = $currentOffset, !6 = $value, !7 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
    5     1        RECV                                                 !1      
    6     2        RECV_INIT                                            !2      0
    7     3        RECV_INIT                                            !3      null
    8     4        RECV_INIT                                            !4      <false>
   10     5        IS_SMALLER                                                   !2, 0
          6      > JMPZ                                                         ~8, ->10
   11     7    >   COUNT                                                ~9      !1
          8        ADD                                                  ~10     ~9, !2
          9        ASSIGN                                                       !2, ~10
   13    10    >   IS_SMALLER                                                   !3, 0
         11      > JMPZ                                                         ~12, ->16
   14    12    >   COUNT                                                ~13     !1
         13        ADD                                                  ~14     ~13, !3
         14        SUB                                                  ~15     ~14, !2
         15        ASSIGN                                                       !3, ~15
   17    16    >   ASSIGN                                                       !5, -1
   18    17      > FE_RESET_R                                           $18     !1, ->45
         18    > > FE_FETCH_R                                           ~19     $18, !6, ->45
         19    >   ASSIGN                                                       !7, ~19
   19    20        PRE_INC                                                      !5
   20    21        IS_SMALLER                                                   !5, !2
         22      > JMPZ                                                         ~22, ->24
   21    23    > > JMP                                                          ->18
   23    24    >   TYPE_CHECK                                      1020  ~23     !3
         25      > JMPZ_EX                                              ~23     ~23, ->29
         26    >   ADD                                                  ~24     !2, !3
         27        IS_SMALLER_OR_EQUAL                                  ~25     ~24, !5
         28        BOOL                                                 ~23     ~25
         29    > > JMPZ                                                         ~23, ->31
   24    30    > > JMP                                                          ->45
   27    31    > > JMPZ_EX                                              ~26     !4, ->34
         32    >   IS_IDENTICAL                                         ~27     !6, !0
         33        BOOL                                                 ~26     ~27
         34    > > JMPNZ_EX                                             ~26     ~26, ->40
   29    35    >   BOOL_NOT                                             ~28     !4
         36      > JMPZ_EX                                              ~28     ~28, ->39
         37    >   IS_EQUAL                                             ~29     !6, !0
         38        BOOL                                                 ~28     ~29
         39    >   BOOL                                                 ~26     ~28
         40    > > JMPZ                                                         ~26, ->44
   31    41    >   VERIFY_RETURN_TYPE                                           !7
         42        FE_FREE                                                      $18
         43      > RETURN                                                       !7
   18    44    > > JMP                                                          ->18
         45    >   FE_FREE                                                      $18
   34    46      > RETURN                                                       <false>
   35    47*       VERIFY_RETURN_TYPE                                           
         48*     > RETURN                                                       null

End of function array_search_range

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.6 ms | 1421 KiB | 18 Q