3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Department { public function __construct( public readonly string $name, public readonly array $employees, ) {} } class Emploee { public function __construct( public readonly string $name, public readonly float $salary, ) {} } $departmentsData = [ 'Purchases' => [ ['count' => 9, 'rank' => 3, 'data' => ['name' => 'Manager', 'salary' => 330.]], ['count' => 3, 'rank' => 2, 'data' => ['name' => 'Manager', 'salary' => 220.]], ], 'Sales' => [ ['count' => 12, 'rank' => 1, 'data' => ['name' => 'Manager', 'salary' => 110.]], ], ]; $departments = []; foreach ($departmentsData as $departmentName => $departmentPositions) { $employees = []; foreach ($departmentPositions as $position) { foreach (range(1, $position['count']) as $index) { $employees[] = new Emploee(...$position['data']); } } $departments[] = new Department($departmentName, $employees); } $totalSalary = 0; foreach ($departments as $department) { foreach ($department->employees as $employee) { $totalSalary += $employee->salary; } } var_dump($totalSalary);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 33
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 33
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 25
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 23
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 25
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 36, Position 2 = 45
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 45
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
2 jumps found. (Code = 78) Position 1 = 40, Position 2 = 43
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 43
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 33
filename:       /in/J6u2D
function name:  (null)
number of ops:  50
compiled vars:  !0 = $departmentsData, !1 = $departments, !2 = $departmentPositions, !3 = $departmentName, !4 = $employees, !5 = $position, !6 = $index, !7 = $totalSalary, !8 = $department, !9 = $employee
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   27     1        ASSIGN                                                   !1, <array>
   28     2      > FE_RESET_R                                       $12     !0, ->33
          3    > > FE_FETCH_R                                       ~13     $12, !2, ->33
          4    >   ASSIGN                                                   !3, ~13
   29     5        ASSIGN                                                   !4, <array>
   30     6      > FE_RESET_R                                       $16     !2, ->25
          7    > > FE_FETCH_R                                               $16, !5, ->25
   31     8    >   INIT_FCALL                                               'range'
          9        SEND_VAL                                                 1
         10        FETCH_DIM_R                                      ~17     !5, 'count'
         11        SEND_VAL                                                 ~17
         12        DO_ICALL                                         $18     
         13      > FE_RESET_R                                       $19     $18, ->23
         14    > > FE_FETCH_R                                               $19, !6, ->23
   32    15    >   NEW                                              $21     'Emploee'
         16        FETCH_DIM_R                                      ~22     !5, 'data'
         17        SEND_UNPACK                                              ~22
         18        CHECK_UNDEF_ARGS                                         
         19        DO_FCALL                                      1          
         20        ASSIGN_DIM                                               !4
         21        OP_DATA                                                  $21
   31    22      > JMP                                                      ->14
         23    >   FE_FREE                                                  $19
   30    24      > JMP                                                      ->7
         25    >   FE_FREE                                                  $16
   36    26        NEW                                              $25     'Department'
         27        SEND_VAR_EX                                              !3
         28        SEND_VAR_EX                                              !4
         29        DO_FCALL                                      0          
         30        ASSIGN_DIM                                               !1
         31        OP_DATA                                                  $25
   28    32      > JMP                                                      ->3
         33    >   FE_FREE                                                  $12
   39    34        ASSIGN                                                   !7, 0
   40    35      > FE_RESET_R                                       $28     !1, ->45
         36    > > FE_FETCH_R                                               $28, !8, ->45
   41    37    >   FETCH_OBJ_R                                      ~29     !8, 'employees'
         38      > FE_RESET_R                                       $30     ~29, ->43
         39    > > FE_FETCH_R                                               $30, !9, ->43
   42    40    >   FETCH_OBJ_R                                      ~31     !9, 'salary'
         41        ASSIGN_OP                                     1          !7, ~31
   41    42      > JMP                                                      ->39
         43    >   FE_FREE                                                  $30
   40    44      > JMP                                                      ->36
         45    >   FE_FREE                                                  $28
   46    46        INIT_FCALL                                               'var_dump'
         47        SEND_VAR                                                 !7
         48        DO_ICALL                                                 
         49      > RETURN                                                   1

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

End of function __construct

End of class Department.

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

End of function __construct

End of class Emploee.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.4 ms | 1008 KiB | 15 Q