3v4l.org

run code in 500+ 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 = 45, Position 2 = 54
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 54
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 32
filename:       /in/ks42p
function name:  (null)
number of ops:  59
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        FRAMELESS_ICALL_2                implode             ~29     '%2C', !1
         42        INIT_ARRAY                                           ~30     ~29
         43        ASSIGN                                                       !8, ~30
   19    44      > FE_RESET_R                                           $32     !2, ->54
         45    > > FE_FETCH_R                                                   $32, !9, ->54
   20    46    >   INIT_FCALL                                                   'array_replace'
         47        SEND_VAR                                                     !7
         48        SEND_VAR                                                     !9
         49        DO_ICALL                                             $34     
         50        FRAMELESS_ICALL_2                implode             ~35     '%2C', $34
         51        ASSIGN_DIM                                                   !8
         52        OP_DATA                                                      ~35
   19    53      > JMP                                                          ->45
         54    >   FE_FREE                                                      $32
   22    55        INIT_FCALL                                                   'var_export'
         56        SEND_VAR                                                     !8
         57        DO_ICALL                                                     
         58      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.12 ms | 1609 KiB | 19 Q