3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTotalHours($companyName) { return ['Company_A' => '20h 45m', 'Company_B' => '7h 30m'][$companyName]; } $array = [ ['user_id' => 255, 'display_name' => 'Mark', 'company_name' => 'Company_A'], ['user_id' => 150, 'display_name' => 'Paul', 'company_name' => 'Company_A'], ['user_id' => 25, 'display_name' => 'Hulk', 'company_name' => 'Company_B'], ['user_id' => 50, 'display_name' => 'Bob', 'company_name' => 'Company_B'], ]; $result = []; foreach ($array as $row) { $cn = $row['company_name']; unset($row['company_name']); $result[$cn]['company_total_hours'] ??= getTotalHours($cn); $result[$cn]['employees'][] = $row; } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 23
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/PvCHH
function name:  (null)
number of ops:  28
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $cn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, <array>
   15     2      > FE_RESET_R                                       $6      !0, ->23
          3    > > FE_FETCH_R                                               $6, !2, ->23
   16     4    >   FETCH_DIM_R                                      ~7      !2, 'company_name'
          5        ASSIGN                                                   !3, ~7
   17     6        UNSET_DIM                                                !2, 'company_name'
   18     7        FETCH_DIM_IS                                     ~9      !1, !3
          8        FETCH_DIM_IS                                     ~10     ~9, 'company_total_hours'
          9        COALESCE                                         ~11     ~10
         10        INIT_FCALL                                               'gettotalhours'
         11        SEND_VAR                                                 !3
         12        DO_FCALL                                      0  $12     
         13        FETCH_DIM_W                                      $13     !1, !3
         14        ASSIGN_DIM                                       ~14     $13, 'company_total_hours'
         15        OP_DATA                                                  $12
         16        QM_ASSIGN                                        ~11     ~14
         17        FREE                                                     ~11
   19    18        FETCH_DIM_W                                      $15     !1, !3
         19        FETCH_DIM_W                                      $16     $15, 'employees'
         20        ASSIGN_DIM                                               $16
         21        OP_DATA                                                  !2
   15    22      > JMP                                                      ->3
         23    >   FE_FREE                                                  $6
   21    24        INIT_FCALL                                               'var_export'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Function gettotalhours:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PvCHH
function name:  getTotalHours
number of ops:  4
compiled vars:  !0 = $companyName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        FETCH_DIM_R                                      ~1      <array>, !0
          2      > RETURN                                                   ~1
    5     3*     > RETURN                                                   null

End of function gettotalhours

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.17 ms | 1013 KiB | 15 Q