3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ ['id' => 1, 'name' => 'foo', 'year' => 2017, 'month' => 1, 'value' => 'bar1'], ['id' => 2, 'name' => 'foo', 'year' => 2017, 'month' => 2, 'value' => 'bar2'], ['id' => 3, 'name' => 'foo', 'year' => 2017, 'month' => 3, 'value' => 'bar3'], ['id' => 4, 'name' => 'foo', 'year' => 2017, 'month' => 4, 'value' => 'bar4'], ]; $data = []; foreach($rows as $row) { $key = $row['name'] . '_' . $row['year']; if(!isset($data[$key])){ $data[$key] = array( 'id' => $row['id'], 'name' => $row['name'], 'year' => $row['year'], ); } $month = 'month' . $row['month']; $data[$key][$month] = $row['value']; } print_r($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/KvCD5
function name:  (null)
number of ops:  33
compiled vars:  !0 = $rows, !1 = $data, !2 = $row, !3 = $key, !4 = $month
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $7      !0, ->28
          3    > > FE_FETCH_R                                               $7, !2, ->28
   12     4    >   FETCH_DIM_R                                      ~8      !2, 'name'
          5        CONCAT                                           ~9      ~8, '_'
          6        FETCH_DIM_R                                      ~10     !2, 'year'
          7        CONCAT                                           ~11     ~9, ~10
          8        ASSIGN                                                   !3, ~11
   13     9        ISSET_ISEMPTY_DIM_OBJ                         0  ~13     !1, !3
         10        BOOL_NOT                                         ~14     ~13
         11      > JMPZ                                                     ~14, ->20
   15    12    >   FETCH_DIM_R                                      ~16     !2, 'id'
         13        INIT_ARRAY                                       ~17     ~16, 'id'
   16    14        FETCH_DIM_R                                      ~18     !2, 'name'
         15        ADD_ARRAY_ELEMENT                                ~17     ~18, 'name'
   17    16        FETCH_DIM_R                                      ~19     !2, 'year'
         17        ADD_ARRAY_ELEMENT                                ~17     ~19, 'year'
   14    18        ASSIGN_DIM                                               !1, !3
   17    19        OP_DATA                                                  ~17
   20    20    >   FETCH_DIM_R                                      ~20     !2, 'month'
         21        CONCAT                                           ~21     'month', ~20
         22        ASSIGN                                                   !4, ~21
   21    23        FETCH_DIM_R                                      ~25     !2, 'value'
         24        FETCH_DIM_W                                      $23     !1, !3
         25        ASSIGN_DIM                                               $23, !4
         26        OP_DATA                                                  ~25
   11    27      > JMP                                                      ->3
         28    >   FE_FREE                                                  $7
   24    29        INIT_FCALL                                               'print_r'
         30        SEND_VAR                                                 !1
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.51 ms | 1003 KiB | 14 Q