3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['model_num' => 'ABC', 'revision' => 'AA', 'testRecipeID' => 85, 'value' => 31.25, 'treatment' => 'Pressure'], ['model_num' => 'ABC', 'revision' => 'AA', 'testRecipeID' => 85, 'value' => 31.25, 'treatment' => 'Gas'], ['model_num' => 'ABC', 'revision' => 'AA', 'testRecipeID' => 85, 'value' => 33.12, 'treatment' => 'Temp'], ['model_num' => 'ABC', 'revision' => 'AA', 'testRecipeID' => 85, 'value' => 25.87, 'treatment' => 'Current'], ['model_num' => 'ABC', 'revision' => 'AB', 'testRecipeID' => 86, 'value' => 26.63, 'treatment' => 'Pressure'], ['model_num' => 'ABC', 'revision' => 'AB', 'testRecipeID' => 86, 'value' => 26.0, 'treatment' => 'Gas'], ['model_num' => 'ABC', 'revision' => 'AB', 'testRecipeID' => 86, 'value' => 23.75, 'treatment' => 'Temp'] ]; $result = []; foreach ($data as $row) { $compositeKey = "{$row['model_num']}-{$row['revision']}-{$row['testRecipeID']}"; $result[$compositeKey] ??= [ 'model_num' => $row['model_num'], 'revision' => $row['revision'], 'testRecipeID' => $row['testRecipeID'] ]; $result[$compositeKey][$row['treatment']] = $row['value']; } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 31
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 31
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/2PPl6
function name:  (null)
number of ops:  39
compiled vars:  !0 = $data, !1 = $result, !2 = $row, !3 = $compositeKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1        ASSIGN                                                   !1, <array>
   13     2      > FE_RESET_R                                       $6      !0, ->31
          3    > > FE_FETCH_R                                               $6, !2, ->31
   14     4    >   FETCH_DIM_R                                      ~7      !2, 'model_num'
          5        ROPE_INIT                                     5  ~11     ~7
          6        ROPE_ADD                                      1  ~11     ~11, '-'
          7        FETCH_DIM_R                                      ~8      !2, 'revision'
          8        ROPE_ADD                                      2  ~11     ~11, ~8
          9        ROPE_ADD                                      3  ~11     ~11, '-'
         10        FETCH_DIM_R                                      ~9      !2, 'testRecipeID'
         11        ROPE_END                                      4  ~10     ~11, ~9
         12        ASSIGN                                                   !3, ~10
   15    13        FETCH_DIM_IS                                     ~15     !1, !3
         14        COALESCE                                         ~16     ~15
   16    15        FETCH_DIM_R                                      ~17     !2, 'model_num'
         16        INIT_ARRAY                                       ~18     ~17, 'model_num'
   17    17        FETCH_DIM_R                                      ~19     !2, 'revision'
         18        ADD_ARRAY_ELEMENT                                ~18     ~19, 'revision'
   18    19        FETCH_DIM_R                                      ~20     !2, 'testRecipeID'
         20        ADD_ARRAY_ELEMENT                                ~18     ~20, 'testRecipeID'
   15    21        ASSIGN_DIM                                       ~21     !1, !3
         22        OP_DATA                                                  ~18
         23        QM_ASSIGN                                        ~16     ~21
         24        FREE                                                     ~16
   20    25        FETCH_DIM_R                                      ~23     !2, 'treatment'
         26        FETCH_DIM_R                                      ~25     !2, 'value'
         27        FETCH_DIM_W                                      $22     !1, !3
         28        ASSIGN_DIM                                               $22, ~23
         29        OP_DATA                                                  ~25
   13    30      > JMP                                                      ->3
         31    >   FE_FREE                                                  $6
   22    32        INIT_FCALL                                               'var_export'
         33        INIT_FCALL                                               'array_values'
         34        SEND_VAR                                                 !1
         35        DO_ICALL                                         $26     
         36        SEND_VAR                                                 $26
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.73 ms | 1004 KiB | 15 Q