3v4l.org

run code in 300+ PHP versions simultaneously
<?php $get_data = array( array( "MenuId" => "1", "MenuName" => "Perencanaan dan Pengadaan", "MenuParent" => "", "MenuLink" => "" ), array( "MenuId" => "1-1", "MenuName" => "RKA / DPA", "MenuParent" => "1", "MenuLink" => "" ), array( "MenuId" => "1-1-1", "MenuName" => "Daftar RKA / DPA", "MenuParent" => "1-1", "MenuLink" => "rkbu" ) ); function insert_into(&$array, array $keys, $value) { $last = array_pop($keys); foreach($keys as $key) { if(!array_key_exists($key, $array) || array_key_exists($key, $array) && !is_array($array[$key]['items'])) { $array[$key]['items'] = array(); } $array = &$array[$key]; } $array[$last] = $value; } $menuItems = array(); foreach($get_data as $item) { $levels = explode('-', $item['MenuId']); insert_into($menuItems, $levels, $item['MenuName']); } print_r($menuItems);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/qfm5q
function name:  (null)
number of ops:  22
compiled vars:  !0 = $get_data, !1 = $menuItems, !2 = $item, !3 = $levels
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   38     1        ASSIGN                                                   !1, <array>
   39     2      > FE_RESET_R                                       $6      !0, ->17
          3    > > FE_FETCH_R                                               $6, !2, ->17
   40     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '-'
          6        FETCH_DIM_R                                      ~7      !2, 'MenuId'
          7        SEND_VAL                                                 ~7
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !3, $8
   41    10        INIT_FCALL                                               'insert_into'
         11        SEND_REF                                                 !1
         12        SEND_VAR                                                 !3
         13        FETCH_DIM_R                                      ~10     !2, 'MenuName'
         14        SEND_VAL                                                 ~10
         15        DO_FCALL                                      0          
   39    16      > JMP                                                      ->3
         17    >   FE_FREE                                                  $6
   44    18        INIT_FCALL                                               'print_r'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function insert_into:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 27
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 27
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 24
Branch analysis from position: 19
Branch analysis from position: 20
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/qfm5q
function name:  insert_into
number of ops:  31
compiled vars:  !0 = $array, !1 = $keys, !2 = $value, !3 = $last, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   25     3        INIT_FCALL                                               'array_pop'
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !3, $5
   27     7      > FE_RESET_R                                       $7      !1, ->27
          8    > > FE_FETCH_R                                               $7, !4, ->27
   28     9    >   ARRAY_KEY_EXISTS                                 ~8      !4, !0
         10        BOOL_NOT                                         ~9      ~8
         11      > JMPNZ_EX                                         ~9      ~9, ->20
   29    12    >   ARRAY_KEY_EXISTS                                 ~10     !4, !0
         13      > JMPZ_EX                                          ~10     ~10, ->19
         14    >   FETCH_DIM_R                                      ~11     !0, !4
         15        FETCH_DIM_R                                      ~12     ~11, 'items'
         16        TYPE_CHECK                                  128  ~13     ~12
         17        BOOL_NOT                                         ~14     ~13
         18        BOOL                                             ~10     ~14
         19    >   BOOL                                             ~9      ~10
         20    > > JMPZ                                                     ~9, ->24
   30    21    >   FETCH_DIM_W                                      $15     !0, !4
         22        ASSIGN_DIM                                               $15, 'items'
         23        OP_DATA                                                  <array>
   33    24    >   FETCH_DIM_W                                      $17     !0, !4
         25        ASSIGN_REF                                               !0, $17
   27    26      > JMP                                                      ->8
         27    >   FE_FREE                                                  $7
   35    28        ASSIGN_DIM                                               !0, !3
         29        OP_DATA                                                  !2
   36    30      > RETURN                                                   null

End of function insert_into

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.41 ms | 1402 KiB | 20 Q