3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['department' => 'Sale', 'month' => 'February', 'value' => 50], ['department' => 'Sale', 'month' => 'March', 'value' => 35], ['department' => 'Sale', 'month' => 'April', 'value' => 65], ['department' => 'Sale', 'month' => 'May', 'value' => 120], ['department' => 'Dispatch', 'month' => 'February', 'value' => 85], ['department' => 'Dispatch', 'month' => 'March', 'value' => 23], ['department' => 'Dispatch', 'month' => 'April', 'value' => 45], ['department' => 'Dispatch', 'month' => 'May', 'value' => 33], ]; $columns = ['Sale', 'Dispatch', 'Support', 'Calibration']; $columnLookup = array_flip($columns); $result = []; foreach ($array as $row) { $rowKey = $row['month']; $colKey = $columnLookup[$row['department']]; $result[$rowKey][$colKey] = $row['value']; } //var_export($result); foreach ($result as $month => $colVals) { printf( "%' 10s\t%d\t%d\t%d\t%d\n", $month, $colVals[0] ?? 0, $colVals[1] ?? 0, $colVals[2] ?? 0, $colVals[3] ?? 0 ); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 44
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 44
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 19
filename:       /in/R3p6g
function name:  (null)
number of ops:  46
compiled vars:  !0 = $array, !1 = $columns, !2 = $columnLookup, !3 = $result, !4 = $row, !5 = $rowKey, !6 = $colKey, !7 = $colVals, !8 = $month
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, <array>
   15     2        INIT_FCALL                                               'array_flip'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $11     
          5        ASSIGN                                                   !2, $11
   16     6        ASSIGN                                                   !3, <array>
   17     7      > FE_RESET_R                                       $14     !0, ->19
          8    > > FE_FETCH_R                                               $14, !4, ->19
   18     9    >   FETCH_DIM_R                                      ~15     !4, 'month'
         10        ASSIGN                                                   !5, ~15
   19    11        FETCH_DIM_R                                      ~17     !4, 'department'
         12        FETCH_DIM_R                                      ~18     !2, ~17
         13        ASSIGN                                                   !6, ~18
   20    14        FETCH_DIM_R                                      ~22     !4, 'value'
         15        FETCH_DIM_W                                      $20     !3, !5
         16        ASSIGN_DIM                                               $20, !6
         17        OP_DATA                                                  ~22
   17    18      > JMP                                                      ->8
         19    >   FE_FREE                                                  $14
   24    20      > FE_RESET_R                                       $23     !3, ->44
         21    > > FE_FETCH_R                                       ~24     $23, !7, ->44
         22    >   ASSIGN                                                   !8, ~24
   25    23        INIT_FCALL                                               'printf'
   26    24        SEND_VAL                                                 '%25%27+10s%09%25d%09%25d%09%25d%09%25d%0A'
   27    25        SEND_VAR                                                 !8
   28    26        FETCH_DIM_IS                                     ~26     !7, 0
         27        COALESCE                                         ~27     ~26
         28        QM_ASSIGN                                        ~27     0
         29        SEND_VAL                                                 ~27
   29    30        FETCH_DIM_IS                                     ~28     !7, 1
         31        COALESCE                                         ~29     ~28
         32        QM_ASSIGN                                        ~29     0
         33        SEND_VAL                                                 ~29
   30    34        FETCH_DIM_IS                                     ~30     !7, 2
         35        COALESCE                                         ~31     ~30
         36        QM_ASSIGN                                        ~31     0
         37        SEND_VAL                                                 ~31
   31    38        FETCH_DIM_IS                                     ~32     !7, 3
         39        COALESCE                                         ~33     ~32
         40        QM_ASSIGN                                        ~33     0
         41        SEND_VAL                                                 ~33
   25    42        DO_ICALL                                                 
   24    43      > JMP                                                      ->21
         44    >   FE_FREE                                                  $23
   33    45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
134.06 ms | 1006 KiB | 15 Q