3v4l.org

run code in 300+ PHP versions simultaneously
<?php function seek(&$arr, $key, $strict = false){ $offset = 0; while( $strict ? key($arr) !== $key : key($arr) != $key ){ next($arr); $offset++; } return $offset; } $arr = [ 'a' => 10, 'b' => 11, 'c' => 12, 'd' => 13, 'e' => 14, ]; $offset = seek($arr, 'c'); var_dump($offset); var_dump(key($arr)); var_dump(current($arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lkrp2
function name:  (null)
number of ops:  22
compiled vars:  !0 = $arr, !1 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'seek'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 'c'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   25     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   26     9        INIT_FCALL                                               'var_dump'
         10        INIT_FCALL                                               'key'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                                 
   27    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'current'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $8      
         19        SEND_VAR                                                 $8
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function seek:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 5
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 5
Branch analysis from position: 22
Branch analysis from position: 5
Branch analysis from position: 16
filename:       /in/lkrp2
function name:  seek
number of ops:  24
compiled vars:  !0 = $arr, !1 = $key, !2 = $strict, !3 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
    4     3        ASSIGN                                                   !3, 0
    6     4      > JMP                                                      ->9
   10     5    >   INIT_FCALL                                               'next'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                                 
   11     8        PRE_INC                                                  !3
    6     9    > > JMPZ                                                     !2, ->16
    7    10    >   INIT_FCALL                                               'key'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $7      
         13        IS_NOT_IDENTICAL                                 ~8      !1, $7
         14        QM_ASSIGN                                        ~9      ~8
         15      > JMP                                                      ->21
    8    16    >   INIT_FCALL                                               'key'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $10     
         19        IS_NOT_EQUAL                                     ~11     !1, $10
         20        QM_ASSIGN                                        ~9      ~11
         21    > > JMPNZ                                                    ~9, ->5
   13    22    > > RETURN                                                   !3
   14    23*     > RETURN                                                   null

End of function seek

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
186.59 ms | 1403 KiB | 22 Q