3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'root/foo/bar/file.jpg'; $parts = explode("/", $str); $leaf = array_pop($parts); $tree = array(); $branch = &$tree; foreach($parts as $v){ $branch[$v] = array(); $branch = &$branch[$v]; } $branch = $leaf; print_r($tree);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/2MitV
function name:  (null)
number of ops:  25
compiled vars:  !0 = $str, !1 = $parts, !2 = $leaf, !3 = $tree, !4 = $branch, !5 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'root%2Ffoo%2Fbar%2Ffile.jpg'
    5     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
    6     6        INIT_FCALL                                               'array_pop'
          7        SEND_REF                                                 !1
          8        DO_ICALL                                         $9      
          9        ASSIGN                                                   !2, $9
    7    10        ASSIGN                                                   !3, <array>
    8    11        ASSIGN_REF                                               !4, !3
    9    12      > FE_RESET_R                                       $13     !1, ->19
         13    > > FE_FETCH_R                                               $13, !5, ->19
   11    14    >   ASSIGN_DIM                                               !4, !5
         15        OP_DATA                                                  <array>
   12    16        FETCH_DIM_W                                      $15     !4, !5
         17        ASSIGN_REF                                               !4, $15
    9    18      > JMP                                                      ->13
         19    >   FE_FREE                                                  $13
   14    20        ASSIGN                                                   !4, !2
   16    21        INIT_FCALL                                               'print_r'
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.76 ms | 1004 KiB | 16 Q