3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array ( array("Make" => "Volvo", "Color" => "red", "Quantity" => 18), array("Make" => "BMW", "Color" => "blue", "Quantity" => 13), array("Make" => "Saab", "Quantity" => 11), array("Make" => "Land Rover", "Color" => "green", "Quantity" => 15) ); echo "<pre>"; //below creates csv //$fp = fopen($cfilename, 'w'); $header = false; foreach ($data as $row) { if (empty($header)) //creates header, chr(9) makes tab delimited { $header = array_keys($row); //fputcsv($fp, $header, chr(9)); $header = array_flip($header); $header = array_map(function($header) { return "";}, $header); } var_dump(array_merge($header, $row)); } fclose($fp); return;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
<pre>array(3) { ["Make"]=> string(5) "Volvo" ["Color"]=> string(3) "red" ["Quantity"]=> int(18) } array(3) { ["Make"]=> string(3) "BMW" ["Color"]=> string(4) "blue" ["Quantity"]=> int(13) } array(3) { ["Make"]=> string(4) "Saab" ["Color"]=> string(0) "" ["Quantity"]=> int(11) } array(3) { ["Make"]=> string(10) "Land Rover" ["Color"]=> string(5) "green" ["Quantity"]=> int(15) } Warning: Undefined variable $fp in /in/fQ4Hm on line 25 Fatal error: Uncaught TypeError: fclose(): Argument #1 ($stream) must be of type resource, null given in /in/fQ4Hm:25 Stack trace: #0 /in/fQ4Hm(25): fclose(NULL) #1 {main} thrown in /in/fQ4Hm on line 25
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <pre>array(3) { ["Make"]=> string(5) "Volvo" ["Color"]=> string(3) "red" ["Quantity"]=> int(18) } array(3) { ["Make"]=> string(3) "BMW" ["Color"]=> string(4) "blue" ["Quantity"]=> int(13) } array(3) { ["Make"]=> string(4) "Saab" ["Color"]=> string(0) "" ["Quantity"]=> int(11) } array(3) { ["Make"]=> string(10) "Land Rover" ["Color"]=> string(5) "green" ["Quantity"]=> int(15) } Warning: Undefined variable $fp in /in/fQ4Hm on line 25 Fatal error: Uncaught TypeError: fclose(): Argument #1 ($stream) must be of type resource, null given in /in/fQ4Hm:25 Stack trace: #0 /in/fQ4Hm(25): fclose(NULL) #1 {main} thrown in /in/fQ4Hm on line 25
Process exited with code 255.
Output for 7.0.0 - 7.0.23, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
<pre>array(3) { ["Make"]=> string(5) "Volvo" ["Color"]=> string(3) "red" ["Quantity"]=> int(18) } array(3) { ["Make"]=> string(3) "BMW" ["Color"]=> string(4) "blue" ["Quantity"]=> int(13) } array(3) { ["Make"]=> string(4) "Saab" ["Color"]=> string(0) "" ["Quantity"]=> int(11) } array(3) { ["Make"]=> string(10) "Land Rover" ["Color"]=> string(5) "green" ["Quantity"]=> int(15) } Notice: Undefined variable: fp in /in/fQ4Hm on line 25 Warning: fclose() expects parameter 1 to be resource, null given in /in/fQ4Hm on line 25
Output for 7.3.32 - 7.3.33
<pre>array(3) { ["Make"]=> string(5) "Volvo" ["Color"]=> string(3) "red" ["Quantity"]=> int(18) } array(3) { ["Make"]=> string(3) "BMW" ["Color"]=> string(4) "blue" ["Quantity"]=> int(13) } array(3) { ["Make"]=> string(4) "Saab" ["Color"]=> string(0) "" ["Quantity"]=> int(11) } array(3) { ["Make"]=> string(10) "Land Rover" ["Color"]=> string(5) "green" ["Quantity"]=> int(15) } Warning: fclose() expects parameter 1 to be resource, null given in /in/fQ4Hm on line 25

preferences:
226.97 ms | 402 KiB | 222 Q