3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Speedy yet memory intensive version $f = fopen('php://memory', 'w+'); foreach($data_source as $row) { // You may configure fputcsv as usual fputcsv($f, $row); } rewind($f); // Important $fp = fopen('final.csv', 'w+'); fputs($fp, stream_get_contents($f)); fclose($fp); fclose($f); // Slower version $fp = fopen('final.csv', 'w+'); foreach($data_source as $row) { // You may configure fputcsv as usual fputcsv($fp, $row); } fclose($fp); ?>
Output for 8.5.3 - 8.5.6
Warning: Undefined variable $data_source in /in/8ei2U on line 5 Warning: foreach() argument must be of type array|object, null given in /in/8ei2U on line 5 Warning: fopen(final.csv): Failed to open stream: Read-only file system in /in/8ei2U on line 10 Fatal error: Uncaught TypeError: fputs(): Argument #1 ($stream) must be of type resource, false given in /in/8ei2U:11 Stack trace: #0 /in/8ei2U(11): fputs(false, '') #1 {main} thrown in /in/8ei2U on line 11
Process exited with code 255.
Output for 8.3.5 - 8.3.18, 8.4.9 - 8.4.21
Warning: Undefined variable $data_source in /in/8ei2U on line 5 Warning: foreach() argument must be of type array|object, null given in /in/8ei2U on line 5 Warning: fopen(): open_basedir restriction in effect. File(final.csv) is not within the allowed path(s): (/tmp:/in:/etc) in /in/8ei2U on line 10 Warning: fopen(final.csv): Failed to open stream: Operation not permitted in /in/8ei2U on line 10 Fatal error: Uncaught TypeError: fputs(): Argument #1 ($stream) must be of type resource, false given in /in/8ei2U:11 Stack trace: #0 /in/8ei2U(11): fputs(false, '') #1 {main} thrown in /in/8ei2U on line 11
Process exited with code 255.

preferences:
52.54 ms | 524 KiB | 4 Q