3v4l.org

run code in 500+ 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 = 36, Position 2 = 49
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 49
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
Branch analysis from position: 16
filename:       /in/OkPoQ
function name:  (null)
number of ops:  52
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        FRAMELESS_ICALL_2                implode             ~23     '%3C%2Fth%3E%3Cth%3E', !2
         33        SEND_VAL                                                     ~23
   24    34        DO_ICALL                                                     
   28    35      > FE_RESET_R                                           $25     !1, ->49
         36    > > FE_FETCH_R                                           ~26     $25, !5, ->49
         37    >   ASSIGN                                                       !6, ~26
   29    38        INIT_FCALL                                                   'printf'
   30    39        SEND_VAL                                                     '%3Ctr%3E%3Ctd%3E%25s%3C%2Ftd%3E%3Ctd%3E%25s%3C%2Ftd%3E%3C%2Ftr%3E%0A'
   31    40        SEND_VAR                                                     !6
   32    41        INIT_FCALL                                                   'array_replace'
         42        SEND_VAR                                                     !4
         43        SEND_VAR                                                     !5
         44        DO_ICALL                                             $28     
         45        FRAMELESS_ICALL_2                implode             ~29     '%3C%2Ftd%3E%3Ctd%3E', $28
         46        SEND_VAL                                                     ~29
   29    47        DO_ICALL                                                     
   28    48      > JMP                                                          ->36
         49    >   FE_FREE                                                      $25
   35    50        ECHO                                                         '%3C%2Ftable%3E'
         51      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
213.37 ms | 2191 KiB | 18 Q