3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ [ 'question_category' => 'Engagement', 'result' => '6.6667', 'employee_first_name' => 'Person A', ], [ 'question_category' => 'Tenure', 'result' => '7.6667', 'employee_first_name' => 'Person A', ], [ 'question_category' => 'Engagement', 'result' => '7.6667', 'employee_first_name' => 'Person B', ], [ 'question_category' => 'Tenure', 'result' => '8.3333', 'employee_first_name' => 'Person B', ], ]; $grouped = []; foreach($data as $row){ // I think this is the mapping? If anything else exists, // this will throw $xOrY = match($row['question_category']){ 'Engagement' => 'x', 'Tenure' => 'y', }; // Group by name $grouped[$row['employee_first_name']][$xOrY] = $row['result']; } // Remove the names (optional) $grouped = array_values($grouped); var_dump($grouped);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
3 jumps found. (Code = 195) Position 1 = 7, Position 2 = 9, Position 3 = 6
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 6
1 jumps found. (Code = 197) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/PN1t4
function name:  (null)
number of ops:  28
compiled vars:  !0 = $data, !1 = $grouped, !2 = $row, !3 = $xOrY
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   26     1        ASSIGN                                                   !1, <array>
   27     2      > FE_RESET_R                                       $6      !0, ->19
          3    > > FE_FETCH_R                                               $6, !2, ->19
   30     4    >   FETCH_DIM_R                                      ~7      !2, 'question_category'
          5      > MATCH                                                    ~7, [ 'Engagement':->7, 'Tenure':->9, ], ->6
          6    > > MATCH_ERROR                                              ~7
   31     7    >   QM_ASSIGN                                        ~9      'x'
          8      > JMP                                                      ->11
   32     9    >   QM_ASSIGN                                        ~9      'y'
         10      > JMP                                                      ->11
         11    >   FREE                                                     ~7
   30    12        ASSIGN                                                   !3, ~9
   36    13        FETCH_DIM_R                                      ~11     !2, 'employee_first_name'
         14        FETCH_DIM_R                                      ~14     !2, 'result'
         15        FETCH_DIM_W                                      $12     !1, ~11
         16        ASSIGN_DIM                                               $12, !3
         17        OP_DATA                                                  ~14
   27    18      > JMP                                                      ->3
         19    >   FE_FREE                                                  $6
   40    20        INIT_FCALL                                               'array_values'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $15     
         23        ASSIGN                                                   !1, $15
   42    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.19 ms | 1069 KiB | 15 Q