3v4l.org

run code in 500+ PHP versions simultaneously
<?php Class Unit{ public function __construct(public readonly ?string $name){} } Class Branch{ public array $units = []; public function __construct(public readonly ?string $name){} } Class Group{ public array $branches = []; public function __construct(public readonly string $name){} } $sampleData = [ ['g1', 'b1', null], ['g1', 'b1', 'u2'], ['g2', null, 'u3'], ['g2', 'b6', 'u4'], ['g3', 'b7', 'u5'], ]; $groups = []; foreach($sampleData as $row){ $groupId = $row[0]; $branchId = $row[1]; $unitId = $row[2]; if(!isset($groups[$groupId])){ $groups[$groupId] = new Group($groupId); } if(!isset($groups[$groupId]->branches[$branchId])){ $groups[$groupId]->branches[$branchId] = new Branch($branchId); } if(!isset($groups[$groupId]->branches[$branchId]->units[$unitId])){ $groups[$groupId]->branches[$branchId]->units[$unitId] = new Unit($unitId); } } var_dump($groups);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 47
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 47
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 30
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 46
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 46
Branch analysis from position: 30
Branch analysis from position: 18
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/WE17l
function name:  (null)
number of ops:  52
compiled vars:  !0 = $sampleData, !1 = $groups, !2 = $row, !3 = $groupId, !4 = $branchId, !5 = $unitId
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                       !0, <array>
   25     1        ASSIGN                                                       !1, <array>
   26     2      > FE_RESET_R                                           $8      !0, ->47
          3    > > FE_FETCH_R                                                   $8, !2, ->47
   27     4    >   FETCH_DIM_R                                          ~9      !2, 0
          5        ASSIGN                                                       !3, ~9
   28     6        FETCH_DIM_R                                          ~11     !2, 1
          7        ASSIGN                                                       !4, ~11
   29     8        FETCH_DIM_R                                          ~13     !2, 2
          9        ASSIGN                                                       !5, ~13
   31    10        ISSET_ISEMPTY_DIM_OBJ                             0  ~15     !1, !3
         11        BOOL_NOT                                             ~16     ~15
         12      > JMPZ                                                         ~16, ->18
   32    13    >   NEW                                                  $18     'Group'
         14        SEND_VAR_EX                                                  !3
         15        DO_FCALL                                          0          
         16        ASSIGN_DIM                                                   !1, !3
         17        OP_DATA                                                      $18
   35    18    >   FETCH_DIM_IS                                         ~20     !1, !3
         19        FETCH_OBJ_IS                                         ~21     ~20, 'branches'
         20        ISSET_ISEMPTY_DIM_OBJ                             0  ~22     ~21, !4
         21        BOOL_NOT                                             ~23     ~22
         22      > JMPZ                                                         ~23, ->30
   36    23    >   NEW                                                  $27     'Branch'
         24        SEND_VAR_EX                                                  !4
         25        DO_FCALL                                          0          
         26        FETCH_DIM_W                                          $24     !1, !3
         27        FETCH_OBJ_W                                          $25     $24, 'branches'
         28        ASSIGN_DIM                                                   $25, !4
         29        OP_DATA                                                      $27
   39    30    >   FETCH_DIM_IS                                         ~29     !1, !3
         31        FETCH_OBJ_IS                                         ~30     ~29, 'branches'
         32        FETCH_DIM_IS                                         ~31     ~30, !4
         33        FETCH_OBJ_IS                                         ~32     ~31, 'units'
         34        ISSET_ISEMPTY_DIM_OBJ                             0  ~33     ~32, !5
         35        BOOL_NOT                                             ~34     ~33
         36      > JMPZ                                                         ~34, ->46
   40    37    >   NEW                                                  $40     'Unit'
         38        SEND_VAR_EX                                                  !5
         39        DO_FCALL                                          0          
         40        FETCH_DIM_W                                          $35     !1, !3
         41        FETCH_OBJ_W                                          $36     $35, 'branches'
         42        FETCH_DIM_W                                          $37     $36, !4
         43        FETCH_OBJ_W                                          $38     $37, 'units'
         44        ASSIGN_DIM                                                   $38, !5
         45        OP_DATA                                                      $40
   26    46    > > JMP                                                          ->3
         47    >   FE_FREE                                                      $8
   46    48        INIT_FCALL                                                   'var_dump'
         49        SEND_VAR                                                     !1
         50        DO_ICALL                                                     
         51      > RETURN                                                       1

Class Unit:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WE17l
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
          1        ASSIGN_OBJ                                                   'name'
          2        OP_DATA                                                      !0
          3      > RETURN                                                       null

End of function __construct

End of class Unit.

Class Branch:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WE17l
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        ASSIGN_OBJ                                                   'name'
          2        OP_DATA                                                      !0
          3      > RETURN                                                       null

End of function __construct

End of class Branch.

Class Group:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WE17l
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        ASSIGN_OBJ                                                   'name'
          2        OP_DATA                                                      !0
          3      > RETURN                                                       null

End of function __construct

End of class Group.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
156.32 ms | 1486 KiB | 14 Q