3v4l.org

run code in 300+ PHP versions simultaneously
<?php $csv = <<<CSV key=a,key2=b,key3=c key=d,key2=e,key4=f,key3=g CSV; $header = []; $rows = []; foreach (explode(PHP_EOL, $csv) as $i => $line) { foreach (str_getcsv($line) as $pair) { [$key, $rows[$i][$key]] = explode('=', $pair, 2); $header[$key] = $key; } } sort($header); $defaults = array_fill_keys($header, 'null'); $result = [implode(',', $header)]; foreach ($rows as $row) { $result[] = implode(',', array_replace($defaults, $row)); } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 32
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 32
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 30
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 30
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 30
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 60
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 60
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 32
filename:       /in/ks42p
function name:  (null)
number of ops:  65
compiled vars:  !0 = $csv, !1 = $header, !2 = $rows, !3 = $line, !4 = $i, !5 = $pair, !6 = $key, !7 = $defaults, !8 = $result, !9 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'key%3Da%2Ckey2%3Db%2Ckey3%3Dc%0Akey%3Dd%2Ckey2%3De%2Ckey4%3Df%2Ckey3%3Dg'
    8     1        ASSIGN                                                   !1, <array>
    9     2        ASSIGN                                                   !2, <array>
   10     3        INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '%0A'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $13     
          7      > FE_RESET_R                                       $14     $13, ->32
          8    > > FE_FETCH_R                                       ~15     $14, !3, ->32
          9    >   ASSIGN                                                   !4, ~15
   11    10        INIT_FCALL                                               'str_getcsv'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $17     
         13      > FE_RESET_R                                       $18     $17, ->30
         14    > > FE_FETCH_R                                               $18, !5, ->30
   12    15    >   INIT_FCALL                                               'explode'
         16        SEND_VAL                                                 '%3D'
         17        SEND_VAR                                                 !5
         18        SEND_VAL                                                 2
         19        DO_ICALL                                         $19     
         20        FETCH_LIST_R                                     $20     $19, 0
         21        ASSIGN                                                   !6, $20
         22        FETCH_LIST_R                                     $22     $19, 1
         23        FETCH_DIM_W                                      $23     !2, !4
         24        ASSIGN_DIM                                               $23, !6
         25        OP_DATA                                                  $22
         26        FREE                                                     $19
   13    27        ASSIGN_DIM                                               !1, !6
         28        OP_DATA                                                  !6
   11    29      > JMP                                                      ->14
         30    >   FE_FREE                                                  $18
   10    31      > JMP                                                      ->8
         32    >   FE_FREE                                                  $14
   16    33        INIT_FCALL                                               'sort'
         34        SEND_REF                                                 !1
         35        DO_ICALL                                                 
   17    36        INIT_FCALL                                               'array_fill_keys'
         37        SEND_VAR                                                 !1
         38        SEND_VAL                                                 'null'
         39        DO_ICALL                                         $27     
         40        ASSIGN                                                   !7, $27
   18    41        INIT_FCALL                                               'implode'
         42        SEND_VAL                                                 '%2C'
         43        SEND_VAR                                                 !1
         44        DO_ICALL                                         $29     
         45        INIT_ARRAY                                       ~30     $29
         46        ASSIGN                                                   !8, ~30
   19    47      > FE_RESET_R                                       $32     !2, ->60
         48    > > FE_FETCH_R                                               $32, !9, ->60
   20    49    >   INIT_FCALL                                               'implode'
         50        SEND_VAL                                                 '%2C'
         51        INIT_FCALL                                               'array_replace'
         52        SEND_VAR                                                 !7
         53        SEND_VAR                                                 !9
         54        DO_ICALL                                         $34     
         55        SEND_VAR                                                 $34
         56        DO_ICALL                                         $35     
         57        ASSIGN_DIM                                               !8
         58        OP_DATA                                                  $35
   19    59      > JMP                                                      ->48
         60    >   FE_FREE                                                  $32
   22    61        INIT_FCALL                                               'var_export'
         62        SEND_VAR                                                 !8
         63        DO_ICALL                                                 
         64      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.34 ms | 1009 KiB | 20 Q