3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ 'plants'=>[ 'fruits'=>['hard'=>'coconut','juicy'=>'mango'], 'non-edible'=>'bambo' ], 'professions'=>[ 'service'=>[ 'contractors'=>['math'=>'accountant'] ], 'industry'=>'engineer' ], 'my_jobs'=>['first'=>'bartender','recent'=>'engineer'] ]; function pathFinder($target, array $source, $parentPath=''){ $results=[]; foreach($source as $k => $v){ $path = $parentPath.'/'.$k; //current path //if element is array, recurse and import found results if(is_array($v) && $result=pathFinder($target, $v,$path)){ foreach($result as $r) array_push($results,$r); } elseif($v===$target) $results[]=$path; //add any match to results } return $results; } print_r(pathFinder('engineer',$array)); print_r(pathFinder('missing data',$array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ndPas
function name:  (null)
number of ops:  16
compiled vars:  !0 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   28     1        INIT_FCALL                                                   'print_r'
          2        INIT_FCALL                                                   'pathfinder'
          3        SEND_VAL                                                     'engineer'
          4        SEND_VAR                                                     !0
          5        DO_FCALL                                          0  $2      
          6        SEND_VAR                                                     $2
          7        DO_ICALL                                                     
   29     8        INIT_FCALL                                                   'print_r'
          9        INIT_FCALL                                                   'pathfinder'
         10        SEND_VAL                                                     'missing+data'
         11        SEND_VAR                                                     !0
         12        DO_FCALL                                          0  $4      
         13        SEND_VAR                                                     $4
         14        DO_ICALL                                                     
         15      > RETURN                                                       1

Function pathfinder:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 34
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 34
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 29
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 27
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 33
Branch analysis from position: 19
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/ndPas
function name:  pathFinder
number of ops:  37
compiled vars:  !0 = $target, !1 = $source, !2 = $parentPath, !3 = $results, !4 = $v, !5 = $k, !6 = $path, !7 = $result, !8 = $r
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      ''
   16     3        ASSIGN                                                       !3, <array>
   17     4      > FE_RESET_R                                           $10     !1, ->34
          5    > > FE_FETCH_R                                           ~11     $10, !4, ->34
          6    >   ASSIGN                                                       !5, ~11
   18     7        CONCAT                                               ~13     !2, '%2F'
          8        CONCAT                                               ~14     ~13, !5
          9        ASSIGN                                                       !6, ~14
   20    10        TYPE_CHECK                                      128  ~16     !4
         11      > JMPZ_EX                                              ~16     ~16, ->19
         12    >   INIT_FCALL_BY_NAME                                           'pathFinder'
         13        SEND_VAR_EX                                                  !0
         14        SEND_VAR_EX                                                  !4
         15        SEND_VAR_EX                                                  !6
         16        DO_FCALL                                          0  $17     
         17        ASSIGN                                               ~18     !7, $17
         18        BOOL                                                 ~16     ~18
         19    > > JMPZ                                                         ~16, ->29
   21    20    > > FE_RESET_R                                           $19     !7, ->27
         21    > > FE_FETCH_R                                                   $19, !8, ->27
         22    >   INIT_FCALL                                                   'array_push'
         23        SEND_REF                                                     !3
         24        SEND_VAR                                                     !8
         25        DO_ICALL                                                     
         26      > JMP                                                          ->21
         27    >   FE_FREE                                                      $19
   20    28      > JMP                                                          ->33
   23    29    >   IS_IDENTICAL                                                 !4, !0
         30      > JMPZ                                                         ~21, ->33
         31    >   ASSIGN_DIM                                                   !3
         32        OP_DATA                                                      !6
   17    33    > > JMP                                                          ->5
         34    >   FE_FREE                                                      $10
   26    35      > RETURN                                                       !3
   27    36*     > RETURN                                                       null

End of function pathfinder

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
202.55 ms | 2490 KiB | 17 Q