3v4l.org

run code in 300+ PHP versions simultaneously
<?php //It is assumed that the sql is perfectly capable of sorting by date ASC, role ASC, name ASC $resultSet = [ ['date' => '01/02/14', 'role' => 'Leader', 'name' => 'Jerry'], ['date' => '01/02/14', 'role' => 'Musician', 'name' => 'Bob'], ['date' => '01/02/14', 'role' => 'Singer', 'name' => 'Carol'], ['date' => '08/02/14', 'role' => 'Leader', 'name' => 'Baz'], ['date' => '08/02/14', 'role' => 'Leader', 'name' => 'Gaz'], ['date' => '08/02/14', 'role' => 'Leader', 'name' => 'Haz'], ['date' => '08/02/14', 'role' => 'Musician', 'name' => 'Charles'], ['date' => '08/02/14', 'role' => 'Singer', 'name' => 'Norman'], ['date' => '15/02/14', 'role' => 'Astronaut', 'name' => 'Neil'], ]; $columnWidth = 20; foreach ($resultSet as ['date' => $date, 'role' => $role, 'name' => $name]) { $nested[$date][$role][] = $name; $dates[$date] = str_pad($date, $columnWidth, " ", STR_PAD_BOTH); $roles[$role] = str_pad($role, $columnWidth, " ", STR_PAD_BOTH); } $totalColumns = count($dates) + 1; // HEADINGS printf( implode("|", array_fill(0, $totalColumns, '%s')) . "\n", str_pad('Roles', $columnWidth, " ", STR_PAD_BOTH), ...array_values($dates) ); // SEPARATOR echo implode("|", array_fill(0, $totalColumns, str_repeat('=', $columnWidth))); // DATA foreach ($roles as $role => $paddedRole) { echo "\n$paddedRole"; foreach ($nested as $date => $roleGroup) { echo '|' . str_pad(implode(', ', $nested[$date][$role] ?? ['-']), $columnWidth, " ", STR_PAD_BOTH); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 32
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 32
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 76, Position 2 = 103
Branch analysis from position: 76
2 jumps found. (Code = 78) Position 1 = 77, Position 2 = 103
Branch analysis from position: 77
2 jumps found. (Code = 77) Position 1 = 82, Position 2 = 101
Branch analysis from position: 82
2 jumps found. (Code = 78) Position 1 = 83, Position 2 = 101
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
Branch analysis from position: 101
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 101
Branch analysis from position: 103
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 103
Branch analysis from position: 32
filename:       /in/qQkKC
function name:  (null)
number of ops:  105
compiled vars:  !0 = $resultSet, !1 = $columnWidth, !2 = $date, !3 = $role, !4 = $name, !5 = $nested, !6 = $dates, !7 = $roles, !8 = $totalColumns, !9 = $paddedRole, !10 = $roleGroup
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, 20
   18     2      > FE_RESET_R                                       $13     !0, ->32
          3    > > FE_FETCH_R                                               $13, $14, ->32
          4    >   FETCH_LIST_R                                     $15     $14, 'date'
          5        ASSIGN                                                   !2, $15
          6        FETCH_LIST_R                                     $17     $14, 'role'
          7        ASSIGN                                                   !3, $17
          8        FETCH_LIST_R                                     $19     $14, 'name'
          9        ASSIGN                                                   !4, $19
         10        FREE                                                     $14
   19    11        FETCH_DIM_W                                      $21     !5, !2
         12        FETCH_DIM_W                                      $22     $21, !3
         13        ASSIGN_DIM                                               $22
         14        OP_DATA                                                  !4
   20    15        INIT_FCALL                                               'str_pad'
         16        SEND_VAR                                                 !2
         17        SEND_VAR                                                 !1
         18        SEND_VAL                                                 '+'
         19        SEND_VAL                                                 2
         20        DO_ICALL                                         $25     
         21        ASSIGN_DIM                                               !6, !2
         22        OP_DATA                                                  $25
   21    23        INIT_FCALL                                               'str_pad'
         24        SEND_VAR                                                 !3
         25        SEND_VAR                                                 !1
         26        SEND_VAL                                                 '+'
         27        SEND_VAL                                                 2
         28        DO_ICALL                                         $27     
         29        ASSIGN_DIM                                               !7, !3
         30        OP_DATA                                                  $27
   18    31      > JMP                                                      ->3
         32    >   FE_FREE                                                  $13
   23    33        COUNT                                            ~28     !6
         34        ADD                                              ~29     ~28, 1
         35        ASSIGN                                                   !8, ~29
   26    36        INIT_FCALL                                               'printf'
   27    37        INIT_FCALL                                               'implode'
         38        SEND_VAL                                                 '%7C'
         39        INIT_FCALL                                               'array_fill'
         40        SEND_VAL                                                 0
         41        SEND_VAR                                                 !8
         42        SEND_VAL                                                 '%25s'
         43        DO_ICALL                                         $31     
         44        SEND_VAR                                                 $31
         45        DO_ICALL                                         $32     
         46        CONCAT                                           ~33     $32, '%0A'
         47        SEND_VAL                                                 ~33
   28    48        INIT_FCALL                                               'str_pad'
         49        SEND_VAL                                                 'Roles'
         50        SEND_VAR                                                 !1
         51        SEND_VAL                                                 '+'
         52        SEND_VAL                                                 2
         53        DO_ICALL                                         $34     
         54        SEND_VAR                                                 $34
   29    55        INIT_FCALL                                               'array_values'
         56        SEND_VAR                                                 !6
         57        DO_ICALL                                         $35     
         58        SEND_UNPACK                                              $35
         59        CHECK_UNDEF_ARGS                                         
   26    60        DO_ICALL                                                 
   33    61        INIT_FCALL                                               'implode'
         62        SEND_VAL                                                 '%7C'
         63        INIT_FCALL                                               'array_fill'
         64        SEND_VAL                                                 0
         65        SEND_VAR                                                 !8
         66        INIT_FCALL                                               'str_repeat'
         67        SEND_VAL                                                 '%3D'
         68        SEND_VAR                                                 !1
         69        DO_ICALL                                         $37     
         70        SEND_VAR                                                 $37
         71        DO_ICALL                                         $38     
         72        SEND_VAR                                                 $38
         73        DO_ICALL                                         $39     
         74        ECHO                                                     $39
   36    75      > FE_RESET_R                                       $40     !7, ->103
         76    > > FE_FETCH_R                                       ~41     $40, !9, ->103
         77    >   ASSIGN                                                   !3, ~41
   37    78        NOP                                                      
         79        FAST_CONCAT                                      ~43     '%0A', !9
         80        ECHO                                                     ~43
   38    81      > FE_RESET_R                                       $44     !5, ->101
         82    > > FE_FETCH_R                                       ~45     $44, !10, ->101
         83    >   ASSIGN                                                   !2, ~45
   39    84        INIT_FCALL                                               'str_pad'
         85        INIT_FCALL                                               'implode'
         86        SEND_VAL                                                 '%2C+'
         87        FETCH_DIM_IS                                     ~47     !5, !2
         88        FETCH_DIM_IS                                     ~48     ~47, !3
         89        COALESCE                                         ~49     ~48
         90        QM_ASSIGN                                        ~49     <array>
         91        SEND_VAL                                                 ~49
         92        DO_ICALL                                         $50     
         93        SEND_VAR                                                 $50
         94        SEND_VAR                                                 !1
         95        SEND_VAL                                                 '+'
         96        SEND_VAL                                                 2
         97        DO_ICALL                                         $51     
         98        CONCAT                                           ~52     '%7C', $51
         99        ECHO                                                     ~52
   38   100      > JMP                                                      ->82
        101    >   FE_FREE                                                  $44
   36   102      > JMP                                                      ->76
        103    >   FE_FREE                                                  $40
   41   104      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.37 ms | 1016 KiB | 19 Q