3v4l.org

run code in 300+ PHP versions simultaneously
<?php $paths = [ "fileZ.php", "folder1/content/file1.php", "folder1/content/file2.php", "folder1/edit/file1.php", "folder1/edit/file2.php", "folder1/pagination/file1.php", "folder1/pagination/file2.php", "folder1/toolbar/file1.php", "folder1/toolbar/file2.php", "folder2/cms/html/file1.php", "folder2/cms/html/file2.php" ]; $result = []; foreach ($paths as $path) { $entries = array_reverse(explode("/", $path)); foreach ($entries as $i=>$entry) { if (!$i) { $item=[$entry]; } else { $item[$entry][key($item)] = array_shift($item); } } $result = array_merge_recursive($result, $item); } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 37
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 37
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 30
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 30
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 30
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/SBPin
function name:  (null)
number of ops:  42
compiled vars:  !0 = $paths, !1 = $result, !2 = $path, !3 = $entries, !4 = $entry, !5 = $i, !6 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, <array>
   17     2      > FE_RESET_R                                       $9      !0, ->37
          3    > > FE_FETCH_R                                               $9, !2, ->37
   18     4    >   INIT_FCALL                                               'array_reverse'
          5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '%2F'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $10     
          9        SEND_VAR                                                 $10
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !3, $11
   19    12      > FE_RESET_R                                       $13     !3, ->30
         13    > > FE_FETCH_R                                       ~14     $13, !4, ->30
         14    >   ASSIGN                                                   !5, ~14
   20    15        BOOL_NOT                                         ~16     !5
         16      > JMPZ                                                     ~16, ->20
   21    17    >   INIT_ARRAY                                       ~17     !4
         18        ASSIGN                                                   !6, ~17
   20    19      > JMP                                                      ->29
   23    20    >   INIT_FCALL                                               'key'
         21        SEND_VAR                                                 !6
         22        DO_ICALL                                         $20     
         23        INIT_FCALL                                               'array_shift'
         24        SEND_REF                                                 !6
         25        DO_ICALL                                         $22     
         26        FETCH_DIM_W                                      $19     !6, !4
         27        ASSIGN_DIM                                               $19, $20
         28        OP_DATA                                                  $22
   19    29    > > JMP                                                      ->13
         30    >   FE_FREE                                                  $13
   26    31        INIT_FCALL                                               'array_merge_recursive'
         32        SEND_VAR                                                 !1
         33        SEND_VAR                                                 !6
         34        DO_ICALL                                         $23     
         35        ASSIGN                                                   !1, $23
   17    36      > JMP                                                      ->3
         37    >   FE_FREE                                                  $9
   28    38        INIT_FCALL                                               'var_export'
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                                 
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.08 ms | 1015 KiB | 19 Q