3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data=array(); $all = array( array('id'=>1,'ParentID'=>'0','type'=>'Men'), array('id'=>2,'ParentID'=>'0','type'=>'Women'), array('id'=>3,'ParentID'=>'0','type'=>'Kids'), array('id'=>4,'ParentID'=>'1','type'=>'Shirt'), array('id'=>5,'ParentID'=>'2','type'=>'Top'), array('id'=>6,'ParentID'=>'3','type'=>'Shoes'), array('id'=>7,'ParentID'=>'4','type'=>'p1'), array('id'=>8,'ParentID'=>'5','type'=>'p1'), array('id'=>9,'ParentID'=>'6','type'=>'p1'), array('id'=>10,'ParentID'=>'4','type'=>'p2'), array('id'=>11,'ParentID'=>'5','type'=>'p2'), array('id'=>12,'ParentID'=>'6','type'=>'p2') ); foreach($all as $key => $val) { if($val['ParentID']==0) { $data[$key]=$val; foreach($all as $k => $v) { if($val['id'] == $v['ParentID']){ $data[$key]['subBranches'][$key]= $v; foreach($all as $a => $s) { if($v['id'] == $s['ParentID']){ $data[$key]['subBranches'][$key]['sub_subBranches'][]= $s; } } } } } } echo "<pre>"; print_r($data); echo json_encode($data); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 39
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 39
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 38
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 37
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 37
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 36
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 35
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 35
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 34
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 35
Branch analysis from position: 36
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 37
Branch analysis from position: 38
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/R9YTG
function name:  (null)
number of ops:  49
compiled vars:  !0 = $data, !1 = $all, !2 = $val, !3 = $key, !4 = $v, !5 = $k, !6 = $s, !7 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
   19     2      > FE_RESET_R                                       $10     !1, ->39
          3    > > FE_FETCH_R                                       ~11     $10, !2, ->39
          4    >   ASSIGN                                                   !3, ~11
   21     5        FETCH_DIM_R                                      ~13     !2, 'ParentID'
          6        IS_EQUAL                                                 ~13, 0
          7      > JMPZ                                                     ~14, ->38
   23     8    >   ASSIGN_DIM                                               !0, !3
          9        OP_DATA                                                  !2
   25    10      > FE_RESET_R                                       $16     !1, ->37
         11    > > FE_FETCH_R                                       ~17     $16, !4, ->37
         12    >   ASSIGN                                                   !5, ~17
   27    13        FETCH_DIM_R                                      ~19     !2, 'id'
         14        FETCH_DIM_R                                      ~20     !4, 'ParentID'
         15        IS_EQUAL                                                 ~19, ~20
         16      > JMPZ                                                     ~21, ->36
   28    17    >   FETCH_DIM_W                                      $22     !0, !3
         18        FETCH_DIM_W                                      $23     $22, 'subBranches'
         19        ASSIGN_DIM                                               $23, !3
         20        OP_DATA                                                  !4
   29    21      > FE_RESET_R                                       $25     !1, ->35
         22    > > FE_FETCH_R                                       ~26     $25, !6, ->35
         23    >   ASSIGN                                                   !7, ~26
   31    24        FETCH_DIM_R                                      ~28     !4, 'id'
         25        FETCH_DIM_R                                      ~29     !6, 'ParentID'
         26        IS_EQUAL                                                 ~28, ~29
         27      > JMPZ                                                     ~30, ->34
   32    28    >   FETCH_DIM_W                                      $31     !0, !3
         29        FETCH_DIM_W                                      $32     $31, 'subBranches'
         30        FETCH_DIM_W                                      $33     $32, !3
         31        FETCH_DIM_W                                      $34     $33, 'sub_subBranches'
         32        ASSIGN_DIM                                               $34
         33        OP_DATA                                                  !6
   29    34    > > JMP                                                      ->22
         35    >   FE_FREE                                                  $25
   25    36    > > JMP                                                      ->11
         37    >   FE_FREE                                                  $16
   19    38    > > JMP                                                      ->3
         39    >   FE_FREE                                                  $10
   39    40        ECHO                                                     '%3Cpre%3E'
         41        INIT_FCALL                                               'print_r'
         42        SEND_VAR                                                 !0
         43        DO_ICALL                                                 
   40    44        INIT_FCALL                                               'json_encode'
         45        SEND_VAR                                                 !0
         46        DO_ICALL                                         $37     
         47        ECHO                                                     $37
   41    48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.2 ms | 1400 KiB | 17 Q