3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isArrayFieldSet(array $array, $field, $separator = '/') { if (strpos($field, $separator) !== false) { $path = explode($separator, $field); $field = array_shift($path); if (!is_null($field) && isset($array[$field])) { if (count($path) > 0) { return isArrayFieldSet($array[$field], implode($separator, $path), $separator); } return true; } else { return false; } } return isset($array[$field]); } $array = [ 'a' => 'test', 'b' => [ 'b2' => 123, 'b3' => [ 'test' => true ] ] ]; $shouldPass = [ 'a', 'b', 'b/b2', 'b/b3', 'b/b3/test' ]; $shouldNotPass = [ 'c', 'b/b1', 'b/b2/bx', 'b/b3/test/x', 'c/L1', 'a/k15', ]; foreach ($shouldPass as $test) { isArrayFieldSet($array, $test, '/'); } foreach ($shouldNotPass as $test) { isArrayFieldSet($array, $test, '/'); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 11
filename:       /in/ehKEI
function name:  (null)
number of ops:  22
compiled vars:  !0 = $array, !1 = $shouldPass, !2 = $shouldNotPass, !3 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, <array>
   33     1        ASSIGN                                                   !1, <array>
   41     2        ASSIGN                                                   !2, <array>
   50     3      > FE_RESET_R                                       $7      !1, ->11
          4    > > FE_FETCH_R                                               $7, !3, ->11
          5    >   INIT_FCALL                                               'isarrayfieldset'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !3
          8        SEND_VAL                                                 '%2F'
          9        DO_FCALL                                      0          
         10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $7
   51    12      > FE_RESET_R                                       $9      !2, ->20
         13    > > FE_FETCH_R                                               $9, !3, ->20
         14    >   INIT_FCALL                                               'isarrayfieldset'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !3
         17        SEND_VAL                                                 '%2F'
         18        DO_FCALL                                      0          
         19      > JMP                                                      ->13
         20    >   FE_FREE                                                  $9
         21      > RETURN                                                   1

Function isarrayfieldset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 42
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 41
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 39
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
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: 23
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ehKEI
function name:  isArrayFieldSet
number of ops:  45
compiled vars:  !0 = $array, !1 = $field, !2 = $separator, !3 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '%2F'
    5     3        INIT_FCALL                                               'strpos'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $4      
          7        TYPE_CHECK                                  1018          $4
          8      > JMPZ                                                     ~5, ->42
    6     9    >   INIT_FCALL                                               'explode'
         10        SEND_VAR                                                 !2
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !3, $6
    7    14        INIT_FCALL                                               'array_shift'
         15        SEND_REF                                                 !3
         16        DO_ICALL                                         $8      
         17        ASSIGN                                                   !1, $8
    9    18        TYPE_CHECK                                    2  ~10     !1
         19        BOOL_NOT                                         ~11     ~10
         20      > JMPZ_EX                                          ~11     ~11, ->23
         21    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !0, !1
         22        BOOL                                             ~11     ~12
         23    > > JMPZ                                                     ~11, ->41
   10    24    >   COUNT                                            ~13     !3
         25        IS_SMALLER                                               0, ~13
         26      > JMPZ                                                     ~14, ->39
   11    27    >   INIT_FCALL_BY_NAME                                       'isArrayFieldSet'
         28        CHECK_FUNC_ARG                                           
         29        FETCH_DIM_FUNC_ARG                               $15     !0, !1
         30        SEND_FUNC_ARG                                            $15
         31        INIT_FCALL                                               'implode'
         32        SEND_VAR                                                 !2
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                         $16     
         35        SEND_VAR_NO_REF_EX                                       $16
         36        SEND_VAR_EX                                              !2
         37        DO_FCALL                                      0  $17     
         38      > RETURN                                                   $17
   13    39    > > RETURN                                                   <true>
         40*       JMP                                                      ->42
   15    41    > > RETURN                                                   <false>
   19    42    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !0, !1
         43      > RETURN                                                   ~18
   20    44*     > RETURN                                                   null

End of function isarrayfieldset

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.84 ms | 1403 KiB | 23 Q