3v4l.org

run code in 300+ 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 = 40
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 40
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/5i3SW
function name:  (null)
number of ops:  45
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, ->40
          3    > > FE_FETCH_R                                               $8, !2, ->40
   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        INIT_FCALL                                               'str_replace'
         11        SEND_VAL                                                 '%2F'
         12        SEND_VAL                                                 '%22%3A%7B%22'
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $12     
         15        CONCAT                                           ~13     '%7B%22', $12
         16        CONCAT                                           ~14     ~13, '%22%7D'
         17        INIT_FCALL                                               'str_repeat'
         18        SEND_VAL                                                 '%7D'
         19        SUB                                              ~15     !3, 1
         20        SEND_VAL                                                 ~15
         21        DO_ICALL                                         $16     
         22        CONCAT                                           ~17     ~14, $16
         23        ASSIGN                                                   !4, ~17
   18    24        INIT_FCALL                                               'preg_replace'
         25        SEND_VAL                                                 '%2F%28.%2A%29%28%5C%7B%29%28.%2A%3F%29%28%5C%7D%29%2F'
         26        SEND_VAL                                                 '%241%5B%243%5D'
         27        SEND_VAR                                                 !4
         28        DO_ICALL                                         $19     
         29        ASSIGN                                                   !5, $19
   19    30        INIT_FCALL                                               'array_merge_recursive'
         31        SEND_VAR                                                 !1
         32        INIT_FCALL                                               'json_decode'
         33        SEND_VAR                                                 !5
         34        SEND_VAL                                                 <true>
         35        DO_ICALL                                         $21     
         36        SEND_VAR                                                 $21
         37        DO_ICALL                                         $22     
         38        ASSIGN                                                   !1, $22
   15    39      > JMP                                                      ->3
         40    >   FE_FREE                                                  $8
   22    41        INIT_FCALL                                               'print_r'
         42        SEND_VAR                                                 !1
         43        DO_ICALL                                                 
         44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.05 ms | 1464 KiB | 20 Q