3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array ( array ( 'UserID' => '5GDPR6LR', 'BatchID' => '1', 'BatchItemID' => '1', 'Categories' => '["1","2"]', 'UserComment' => 'first comment', ) , array ( 'UserID' => '5GDPR6LR', 'BatchID' => '1', 'BatchItemID' => '2', 'Categories' => '["3","4"]', 'UserComment' => 'second comment', ) , array ( 'UserID' => '5GDPR6LR', 'BatchID' => '1', 'BatchItemID' => '3', 'Categories' => '["5","6"]', 'UserComment' => 'third comment', ) , ); $headers = array_keys($data[0]); echo '<pre>ARRAY TO WRITE TO FILE:<br>'; print_r($data); echo '</pre><hr>'; $responseFile = '/tmp/12'; $fp = fopen($responseFile, 'w'); fputcsv($fp, $headers, ",", "\"", "\\", "\n"); $lastrow = array(); foreach ($data as $row) { echo '<pre>LASTROW:'; print_r($lastrow); echo '</pre>'; echo '<pre>THISROW:'; print_r($row); echo '</pre>'; if ($row !== $lastrow) { fputcsv($fp, $row, ",", "\"", "\\", "\n"); echo '<pre>ROW WRITTEN TO CSV:'; print_r($row); echo '</pre>'; } $lastrow = $row; } fclose($fp); echo "\n".file_get_contents('/tmp/12') ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 55
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 55
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 53
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 53
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
filename:       /in/f662M
function name:  (null)
number of ops:  65
compiled vars:  !0 = $data, !1 = $headers, !2 = $responseFile, !3 = $fp, !4 = $lastrow, !5 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   35     1        INIT_FCALL                                               'array_keys'
          2        FETCH_DIM_R                                      ~7      !0, 0
          3        SEND_VAL                                                 ~7
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !1, $8
   37     6        ECHO                                                     '%3Cpre%3EARRAY+TO+WRITE+TO+FILE%3A%3Cbr%3E'
          7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                                 
         10        ECHO                                                     '%3C%2Fpre%3E%3Chr%3E'
   39    11        ASSIGN                                                   !2, '%2Ftmp%2F12'
   41    12        INIT_FCALL                                               'fopen'
         13        SEND_VAR                                                 !2
         14        SEND_VAL                                                 'w'
         15        DO_ICALL                                         $12     
         16        ASSIGN                                                   !3, $12
   42    17        INIT_FCALL                                               'fputcsv'
         18        SEND_VAR                                                 !3
         19        SEND_VAR                                                 !1
         20        SEND_VAL                                                 '%2C'
         21        SEND_VAL                                                 '%22'
         22        SEND_VAL                                                 '%5C'
         23        SEND_VAL                                                 '%0A'
         24        DO_ICALL                                                 
   44    25        ASSIGN                                                   !4, <array>
   46    26      > FE_RESET_R                                       $16     !0, ->55
         27    > > FE_FETCH_R                                               $16, !5, ->55
   47    28    >   ECHO                                                     '%3Cpre%3ELASTROW%3A'
         29        INIT_FCALL                                               'print_r'
         30        SEND_VAR                                                 !4
         31        DO_ICALL                                                 
         32        ECHO                                                     '%3C%2Fpre%3E'
   48    33        ECHO                                                     '%3Cpre%3ETHISROW%3A'
         34        INIT_FCALL                                               'print_r'
         35        SEND_VAR                                                 !5
         36        DO_ICALL                                                 
         37        ECHO                                                     '%3C%2Fpre%3E'
   50    38        IS_NOT_IDENTICAL                                         !5, !4
         39      > JMPZ                                                     ~19, ->53
   51    40    >   INIT_FCALL                                               'fputcsv'
         41        SEND_VAR                                                 !3
         42        SEND_VAR                                                 !5
         43        SEND_VAL                                                 '%2C'
         44        SEND_VAL                                                 '%22'
         45        SEND_VAL                                                 '%5C'
         46        SEND_VAL                                                 '%0A'
         47        DO_ICALL                                                 
   52    48        ECHO                                                     '%3Cpre%3EROW+WRITTEN+TO+CSV%3A'
         49        INIT_FCALL                                               'print_r'
         50        SEND_VAR                                                 !5
         51        DO_ICALL                                                 
         52        ECHO                                                     '%3C%2Fpre%3E'
   54    53    >   ASSIGN                                                   !4, !5
   46    54      > JMP                                                      ->27
         55    >   FE_FREE                                                  $16
   57    56        INIT_FCALL                                               'fclose'
         57        SEND_VAR                                                 !3
         58        DO_ICALL                                                 
   59    59        INIT_FCALL                                               'file_get_contents'
         60        SEND_VAL                                                 '%2Ftmp%2F12'
         61        DO_ICALL                                         $24     
         62        CONCAT                                           ~25     '%0A', $24
         63        ECHO                                                     ~25
   61    64      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
256.96 ms | 1021 KiB | 20 Q