3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = Array ( 0 => 'Accessories/Apron', 1 => 'Accessories/Banners', 2 => 'Accessories/Belts', 3 => 'Brand/Brand1', 4 => 'Brand/Brand2', 5 => 'Apparel/Men/Belts', 6 => 'Apparel/Men/Socks', 7 => 'Apparel/Women/Leggings' ); $result =[]; foreach($arr as $val){ $count = count(explode("/", $val)); $str = '{"' . str_replace('/', '":{"', $val) . '"}' . str_repeat("}", $count-1); $json = preg_replace("/(.*)(\{)(.*?)(\})/", "$1[$3]", $str); $result = array_merge_recursive($result, json_decode($json, true)); } Print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 34
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 34
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/5i3SW
function name:  (null)
number of ops:  39
compiled vars:  !0 = $arr, !1 = $result, !2 = $val, !3 = $count, !4 = $str, !5 = $json
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   14     1        ASSIGN                                                       !1, <array>
   15     2      > FE_RESET_R                                           $8      !0, ->34
          3    > > FE_FETCH_R                                                   $8, !2, ->34
   16     4    >   INIT_FCALL                                                   'explode'
          5        SEND_VAL                                                     '%2F'
          6        SEND_VAR                                                     !2
          7        DO_ICALL                                             $9      
          8        COUNT                                                ~10     $9
          9        ASSIGN                                                       !3, ~10
   17    10        FRAMELESS_ICALL_3                str_replace         ~12     '%2F', '%22%3A%7B%22'
         11        OP_DATA                                                      !2
         12        CONCAT                                               ~13     '%7B%22', ~12
         13        CONCAT                                               ~14     ~13, '%22%7D'
         14        INIT_FCALL                                                   'str_repeat'
         15        SEND_VAL                                                     '%7D'
         16        SUB                                                  ~15     !3, 1
         17        SEND_VAL                                                     ~15
         18        DO_ICALL                                             $16     
         19        CONCAT                                               ~17     ~14, $16
         20        ASSIGN                                                       !4, ~17
   18    21        FRAMELESS_ICALL_3                preg_replace        ~19     '%2F%28.%2A%29%28%5C%7B%29%28.%2A%3F%29%28%5C%7D%29%2F', '%241%5B%243%5D'
         22        OP_DATA                                                      !4
         23        ASSIGN                                                       !5, ~19
   19    24        INIT_FCALL                                                   'array_merge_recursive'
         25        SEND_VAR                                                     !1
         26        INIT_FCALL                                                   'json_decode'
         27        SEND_VAR                                                     !5
         28        SEND_VAL                                                     <true>
         29        DO_ICALL                                             $21     
         30        SEND_VAR                                                     $21
         31        DO_ICALL                                             $22     
         32        ASSIGN                                                       !1, $22
   15    33      > JMP                                                          ->3
         34    >   FE_FREE                                                      $8
   22    35        INIT_FCALL                                                   'print_r'
         36        SEND_VAR                                                     !1
         37        DO_ICALL                                                     
         38      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
129.42 ms | 487 KiB | 12 Q