3v4l.org

run code in 300+ PHP versions simultaneously
<?php $resultObject = [ ['name' => 'Tom', 'value' => 15, 'year' => 2018], ['name' => 'Tom', 'value' => 4, 'year' => 2019], ['name' => 'Tom', 'value' => 6, 'year' => 2020], ['name' => 'Kate', 'value' => 18, 'year' => 2018], ['name' => 'Kate', 'value' => 20, 'year' => 2019], ]; $grouped = []; $columns = []; foreach ($resultObject as $row) { $grouped[$row['name']][$row['year']] = $row['value']; $columns[$row['year']] = $row['year']; } sort($columns); $defaults = array_fill_keys($columns, '-'); array_unshift($columns, 'name'); echo "<table>\n"; printf( "<tr><th>%s</th></tr>\n", implode('</th><th>', $columns) ); foreach ($grouped as $name => $records) { printf( "<tr><td>%s</td><td>%s</td></tr>\n", $name, implode('</td><td>', array_replace($defaults, $records)) ); } echo "</table>";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 39, Position 2 = 55
Branch analysis from position: 39
2 jumps found. (Code = 78) Position 1 = 40, Position 2 = 55
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
Branch analysis from position: 16
filename:       /in/OkPoQ
function name:  (null)
number of ops:  58
compiled vars:  !0 = $resultObject, !1 = $grouped, !2 = $columns, !3 = $row, !4 = $defaults, !5 = $records, !6 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2        ASSIGN                                                   !2, <array>
   14     3      > FE_RESET_R                                       $10     !0, ->16
          4    > > FE_FETCH_R                                               $10, !3, ->16
   15     5    >   FETCH_DIM_R                                      ~11     !3, 'name'
          6        FETCH_DIM_R                                      ~13     !3, 'year'
          7        FETCH_DIM_R                                      ~15     !3, 'value'
          8        FETCH_DIM_W                                      $12     !1, ~11
          9        ASSIGN_DIM                                               $12, ~13
         10        OP_DATA                                                  ~15
   16    11        FETCH_DIM_R                                      ~16     !3, 'year'
         12        FETCH_DIM_R                                      ~18     !3, 'year'
         13        ASSIGN_DIM                                               !2, ~16
         14        OP_DATA                                                  ~18
   14    15      > JMP                                                      ->4
         16    >   FE_FREE                                                  $10
   19    17        INIT_FCALL                                               'sort'
         18        SEND_REF                                                 !2
         19        DO_ICALL                                                 
   20    20        INIT_FCALL                                               'array_fill_keys'
         21        SEND_VAR                                                 !2
         22        SEND_VAL                                                 '-'
         23        DO_ICALL                                         $20     
         24        ASSIGN                                                   !4, $20
   21    25        INIT_FCALL                                               'array_unshift'
         26        SEND_REF                                                 !2
         27        SEND_VAL                                                 'name'
         28        DO_ICALL                                                 
   23    29        ECHO                                                     '%3Ctable%3E%0A'
   24    30        INIT_FCALL                                               'printf'
   25    31        SEND_VAL                                                 '%3Ctr%3E%3Cth%3E%25s%3C%2Fth%3E%3C%2Ftr%3E%0A'
   26    32        INIT_FCALL                                               'implode'
         33        SEND_VAL                                                 '%3C%2Fth%3E%3Cth%3E'
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                         $23     
         36        SEND_VAR                                                 $23
   24    37        DO_ICALL                                                 
   28    38      > FE_RESET_R                                       $25     !1, ->55
         39    > > FE_FETCH_R                                       ~26     $25, !5, ->55
         40    >   ASSIGN                                                   !6, ~26
   29    41        INIT_FCALL                                               'printf'
   30    42        SEND_VAL                                                 '%3Ctr%3E%3Ctd%3E%25s%3C%2Ftd%3E%3Ctd%3E%25s%3C%2Ftd%3E%3C%2Ftr%3E%0A'
   31    43        SEND_VAR                                                 !6
   32    44        INIT_FCALL                                               'implode'
         45        SEND_VAL                                                 '%3C%2Ftd%3E%3Ctd%3E'
         46        INIT_FCALL                                               'array_replace'
         47        SEND_VAR                                                 !4
         48        SEND_VAR                                                 !5
         49        DO_ICALL                                         $28     
         50        SEND_VAR                                                 $28
         51        DO_ICALL                                         $29     
         52        SEND_VAR                                                 $29
   29    53        DO_ICALL                                                 
   28    54      > JMP                                                      ->39
         55    >   FE_FREE                                                  $25
   35    56        ECHO                                                     '%3C%2Ftable%3E'
         57      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
206.6 ms | 1010 KiB | 19 Q