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 git.master, git.master_jit, rfc.property-hooks
<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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.83 ms | 402 KiB | 8 Q