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') ?>
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.15, 8.5.0
<pre>ARRAY TO WRITE TO FILE:<br>Array ( [0] => Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 1 [Categories] => ["1","2"] [UserComment] => first comment ) [1] => Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 2 [Categories] => ["3","4"] [UserComment] => second comment ) [2] => Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 3 [Categories] => ["5","6"] [UserComment] => third comment ) ) </pre><hr><pre>LASTROW:Array ( ) </pre><pre>THISROW:Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 1 [Categories] => ["1","2"] [UserComment] => first comment ) </pre><pre>ROW WRITTEN TO CSV:Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 1 [Categories] => ["1","2"] [UserComment] => first comment ) </pre><pre>LASTROW:Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 1 [Categories] => ["1","2"] [UserComment] => first comment ) </pre><pre>THISROW:Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 2 [Categories] => ["3","4"] [UserComment] => second comment ) </pre><pre>ROW WRITTEN TO CSV:Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 2 [Categories] => ["3","4"] [UserComment] => second comment ) </pre><pre>LASTROW:Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 2 [Categories] => ["3","4"] [UserComment] => second comment ) </pre><pre>THISROW:Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 3 [Categories] => ["5","6"] [UserComment] => third comment ) </pre><pre>ROW WRITTEN TO CSV:Array ( [UserID] => 5GDPR6LR [BatchID] => 1 [BatchItemID] => 3 [Categories] => ["5","6"] [UserComment] => third comment ) </pre> UserID,BatchID,BatchItemID,Categories,UserComment 5GDPR6LR,1,1,"[""1"",""2""]","first comment" 5GDPR6LR,1,2,"[""3"",""4""]","second comment" 5GDPR6LR,1,3,"[""5"",""6""]","third comment"
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.

preferences:
80.29 ms | 409 KiB | 5 Q