3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sov_find_key($findvalue, $array, $increment) { reset($array); $key = array_search($findvalue, $array); if ($key === false || $key === 0){ return false; } if ($increment === 0){ return $key; } $isNegative = $increment < 0 ? true:false; $increment = abs($increment); while(key($array) !== $key) { next($array); } $x=0; while($x < $increment) { if( $isNegative ){ prev($array); } else { next($array); } $x++; } return key($array); } $findvalue = '3'; $array = array( 'A' => 'CONTRACTS', 'B' => '1', 'C' => '2', 'D' => '3', 'E' => '4', 'F' => '5', 'G' => '6'); echo sov_find_key($findvalue, $array, -1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CSSmR
function name:  (null)
number of ops:  9
compiled vars:  !0 = $findvalue, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, '3'
   37     1        ASSIGN                                                   !1, <array>
   46     2        INIT_FCALL                                               'sov_find_key'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 -1
          6        DO_FCALL                                      0  $4      
          7        ECHO                                                     $4
          8      > RETURN                                                   1

Function sov_find_key:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 31
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 41
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 46
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 41
Branch analysis from position: 52
Branch analysis from position: 41
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 41
Branch analysis from position: 52
Branch analysis from position: 41
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 31
Branch analysis from position: 39
Branch analysis from position: 31
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 15
filename:       /in/CSSmR
function name:  sov_find_key
number of ops:  57
compiled vars:  !0 = $findvalue, !1 = $array, !2 = $increment, !3 = $key, !4 = $isNegative, !5 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    4     3        INIT_FCALL                                               'reset'
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
    5     6        INIT_FCALL                                               'array_search'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !3, $7
    7    11        TYPE_CHECK                                    4  ~9      !3
         12      > JMPNZ_EX                                         ~9      ~9, ->15
         13    >   IS_IDENTICAL                                     ~10     !3, 0
         14        BOOL                                             ~9      ~10
         15    > > JMPZ                                                     ~9, ->17
    8    16    > > RETURN                                                   <false>
   11    17    >   IS_IDENTICAL                                             !2, 0
         18      > JMPZ                                                     ~11, ->20
   12    19    > > RETURN                                                   !3
   15    20    >   IS_SMALLER                                               !2, 0
         21      > JMPZ                                                     ~12, ->24
         22    >   QM_ASSIGN                                        ~13     <true>
         23      > JMP                                                      ->25
         24    >   QM_ASSIGN                                        ~13     <false>
         25    >   ASSIGN                                                   !4, ~13
   16    26        INIT_FCALL                                               'abs'
         27        SEND_VAR                                                 !2
         28        DO_ICALL                                         $15     
         29        ASSIGN                                                   !2, $15
   18    30      > JMP                                                      ->34
   19    31    >   INIT_FCALL                                               'next'
         32        SEND_REF                                                 !1
         33        DO_ICALL                                                 
   18    34    >   INIT_FCALL                                               'key'
         35        SEND_VAR                                                 !1
         36        DO_ICALL                                         $18     
         37        IS_NOT_IDENTICAL                                         !3, $18
         38      > JMPNZ                                                    ~19, ->31
   22    39    >   ASSIGN                                                   !5, 0
   23    40      > JMP                                                      ->50
   24    41    > > JMPZ                                                     !4, ->46
   25    42    >   INIT_FCALL                                               'prev'
         43        SEND_REF                                                 !1
         44        DO_ICALL                                                 
   24    45      > JMP                                                      ->49
   27    46    >   INIT_FCALL                                               'next'
         47        SEND_REF                                                 !1
         48        DO_ICALL                                                 
   29    49    >   PRE_INC                                                  !5
   23    50    >   IS_SMALLER                                               !5, !2
         51      > JMPNZ                                                    ~24, ->41
   32    52    >   INIT_FCALL                                               'key'
         53        SEND_VAR                                                 !1
         54        DO_ICALL                                         $25     
         55      > RETURN                                                   $25
   33    56*     > RETURN                                                   null

End of function sov_find_key

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.69 ms | 1010 KiB | 20 Q