3v4l.org

run code in 500+ PHP versions simultaneously
<?php //{1,22,56,53,34,51,77}这是一个数组,如何不用内部函数和遍历数组的方法判断出 53 在这个数组里。(面试问题) $arr = array(1,22,56,53,34,51,77); function find($item, array $arr, array $currentIndex = array(0)) { $currentIndex = $currentIndex[0]; if (!isset($arr[$currentIndex])) { return false; } if (isset($arr[$currentIndex]) && ($item === $arr[$currentIndex])) { return true; } var_dump($currentIndex); $currentIndex++; $currentIndex = array($currentIndex); return find($item, $arr, $currentIndex); } $exists = find(53, $arr); var_dump($exists);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AdKW4
function name:  (null)
number of ops:  10
compiled vars:  !0 = $arr, !1 = $exists
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   21     1        INIT_FCALL                                                   'find'
          2        SEND_VAL                                                     53
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $3      
          5        ASSIGN                                                       !1, $3
   22     6        INIT_FCALL                                                   'var_dump'
          7        SEND_VAR                                                     !1
          8        DO_ICALL                                                     
          9      > RETURN                                                       1

Function find:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/AdKW4
function name:  find
number of ops:  29
compiled vars:  !0 = $item, !1 = $arr, !2 = $currentIndex
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      <array>
    6     3        FETCH_DIM_R                                          ~3      !2, 0
          4        ASSIGN                                                       !2, ~3
    7     5        ISSET_ISEMPTY_DIM_OBJ                             0  ~5      !1, !2
          6        BOOL_NOT                                             ~6      ~5
          7      > JMPZ                                                         ~6, ->9
    8     8    > > RETURN                                                       <false>
   11     9    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~7      !1, !2
         10      > JMPZ_EX                                              ~7      ~7, ->14
         11    >   FETCH_DIM_R                                          ~8      !1, !2
         12        IS_IDENTICAL                                         ~9      !0, ~8
         13        BOOL                                                 ~7      ~9
         14    > > JMPZ                                                         ~7, ->16
   12    15    > > RETURN                                                       <true>
   14    16    >   INIT_FCALL                                                   'var_dump'
         17        SEND_VAR                                                     !2
         18        DO_ICALL                                                     
   16    19        PRE_INC                                                      !2
   17    20        INIT_ARRAY                                           ~12     !2
         21        ASSIGN                                                       !2, ~12
   18    22        INIT_FCALL_BY_NAME                                           'find'
         23        SEND_VAR_EX                                                  !0
         24        SEND_VAR_EX                                                  !1
         25        SEND_VAR_EX                                                  !2
         26        DO_FCALL                                          0  $14     
         27      > RETURN                                                       $14
   19    28*     > RETURN                                                       null

End of function find

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
226.8 ms | 2940 KiB | 15 Q