3v4l.org

run code in 300+ PHP versions simultaneously
<?php $directoryTree = [ 'accounting' => [ 'documents' => [ ], 'losses' => [ ], 'profit' => [ ] ], 'legal' => [ 'documents' => [ ] ] ]; $fileList = [ [ 'name' => 'Overview.doc', 'dir_path' => [] ], [ 'name' => 'Incorporation.doc', 'dir_path' => [] ], [ 'name' => 'Profit And Loss.xls', 'dir_path' => ['accounting'] ], [ 'name' => 'Profit 1.xls', 'dir_path' => ['accounting', 'profit'] ], [ 'name' => 'Loss 1.xls', 'dir_path' => ['accounting', 'losses'] ], [ 'name' => 'TOS Draft.doc', 'dir_path' => ['legal', 'documents'] ], [ 'name' => 'Accounting Doc.pdf', 'dir_path' => ['accounting', 'documents'] ], ]; function addFiles2DirectoryTree(array $files, array $directoryTree){ foreach($files as $file) assignFileToPath($file["name"], $file["dir_path"], $directoryTree); return $directoryTree; } function assignFileToPath($filename, $path, &$directoryTree){ while($key = array_shift($path)) $directoryTree = &$directoryTree[$key]; $directoryTree[] = $filename; } $finalOutput = addFiles2DirectoryTree($fileList, $directoryTree); print_r($finalOutput);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ai9Uh
function name:  (null)
number of ops:  11
compiled vars:  !0 = $directoryTree, !1 = $fileList, !2 = $finalOutput
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   24     1        ASSIGN                                                   !1, <array>
   81     2        INIT_FCALL                                               'addfiles2directorytree'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !2, $5
   82     7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function addfiles2directorytree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/Ai9Uh
function name:  addFiles2DirectoryTree
number of ops:  17
compiled vars:  !0 = $files, !1 = $directoryTree, !2 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   65     2      > FE_RESET_R                                       $3      !0, ->14
          3    > > FE_FETCH_R                                               $3, !2, ->14
   66     4    >   INIT_FCALL_BY_NAME                                       'assignFileToPath'
          5        CHECK_FUNC_ARG                                           
          6        FETCH_DIM_FUNC_ARG                               $4      !2, 'name'
          7        SEND_FUNC_ARG                                            $4
          8        CHECK_FUNC_ARG                                           
          9        FETCH_DIM_FUNC_ARG                               $5      !2, 'dir_path'
         10        SEND_FUNC_ARG                                            $5
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0          
   65    13      > JMP                                                      ->3
         14    >   FE_FREE                                                  $3
   68    15      > RETURN                                                   !1
   70    16*     > RETURN                                                   null

End of function addfiles2directorytree

Function assignfiletopath:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
Branch analysis from position: 4
filename:       /in/Ai9Uh
function name:  assignFileToPath
number of ops:  14
compiled vars:  !0 = $filename, !1 = $path, !2 = $directoryTree, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   74     3      > JMP                                                      ->6
   75     4    >   FETCH_DIM_W                                      $4      !2, !3
          5        ASSIGN_REF                                               !2, $4
   74     6    >   INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !1
          8        DO_ICALL                                         $6      
          9        ASSIGN                                           ~7      !3, $6
         10      > JMPNZ                                                    ~7, ->4
   77    11    >   ASSIGN_DIM                                               !2
         12        OP_DATA                                                  !0
   79    13      > RETURN                                                   null

End of function assignfiletopath

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.73 ms | 1403 KiB | 18 Q