3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'Id' => 1, 'Title' => 'Some Text1', 'Children' => [ [ 'Id' => 22, 'Title' => 'Some Text22', 'Children' => [ [ 'Id' => 333, 'Title' => 'Some Text333' ], [ 'Id' => 334, 'Title' => 'Some Text334', 'Children' => [ [ 'Id' => 4444, 'Title' => 'Some Text4443' ] ] ] ] ], [ 'Id' => 23, 'Title' => 'Some Text23', 'Children' => [ [ 'Id' => 335, 'Title' => 'Some Text335' ] ] ] ] ], [ 'Id' => 2, 'Title' => 'Some Text2', ] ]; function pathFinder(array $array, string $find, string $path = ''): array { $paths = []; foreach ($array as $item) { $currentPath = $path . ($path ? ' -> ' : '') . $item['Id']; if (str_contains($item['Title'], $find)) { $paths[] = $currentPath; } if (isset($item['Children'])) { array_push( $paths, ...pathFinder($item['Children'], $find, $currentPath) ); } } return $paths; } var_export( pathFinder($array, 'Some Text335') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AU68N
function name:  (null)
number of ops:  9
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   64     1        INIT_FCALL                                               'var_export'
   65     2        INIT_FCALL                                               'pathfinder'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'Some+Text335'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
   64     7        DO_ICALL                                                 
   66     8      > RETURN                                                   1

Function pathfinder:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 37
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 37
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 36
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 36
Branch analysis from position: 22
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
Branch analysis from position: 22
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/AU68N
function name:  pathFinder
number of ops:  42
compiled vars:  !0 = $array, !1 = $find, !2 = $path, !3 = $paths, !4 = $item, !5 = $currentPath
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      ''
   47     3        ASSIGN                                                   !3, <array>
   48     4      > FE_RESET_R                                       $7      !0, ->37
          5    > > FE_FETCH_R                                               $7, !4, ->37
   49     6    > > JMPZ                                                     !2, ->9
          7    >   QM_ASSIGN                                        ~8      '+-%3E+'
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~8      ''
         10    >   CONCAT                                           ~9      !2, ~8
         11        FETCH_DIM_R                                      ~10     !4, 'Id'
         12        CONCAT                                           ~11     ~9, ~10
         13        ASSIGN                                                   !5, ~11
   51    14        INIT_FCALL                                               'str_contains'
         15        FETCH_DIM_R                                      ~13     !4, 'Title'
         16        SEND_VAL                                                 ~13
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $14     
         19      > JMPZ                                                     $14, ->22
   52    20    >   ASSIGN_DIM                                               !3
         21        OP_DATA                                                  !5
   55    22    >   ISSET_ISEMPTY_DIM_OBJ                         0          !4, 'Children'
         23      > JMPZ                                                     ~16, ->36
   56    24    >   INIT_FCALL                                               'array_push'
   57    25        SEND_REF                                                 !3
   58    26        INIT_FCALL_BY_NAME                                       'pathFinder'
         27        CHECK_FUNC_ARG                                           
         28        FETCH_DIM_FUNC_ARG                               $17     !4, 'Children'
         29        SEND_FUNC_ARG                                            $17
         30        SEND_VAR_EX                                              !1
         31        SEND_VAR_EX                                              !5
         32        DO_FCALL                                      0  $18     
         33        SEND_UNPACK                                              $18
         34        CHECK_UNDEF_ARGS                                         
   56    35        DO_ICALL                                                 
   48    36    > > JMP                                                      ->5
         37    >   FE_FREE                                                  $7
   62    38        VERIFY_RETURN_TYPE                                       !3
         39      > RETURN                                                   !3
   63    40*       VERIFY_RETURN_TYPE                                       
         41*     > RETURN                                                   null

End of function pathfinder

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.38 ms | 1020 KiB | 17 Q