3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[{"macAddress":"xx:xx:xx:xx:xx:xx","lastData":{"dateutc":1595258880000,"tempinf":74.3,"humidityin":44,"baromrelin":29.929,"baromabsin":29.235,"tempf":85.5,"battout":1,"humidity":62,"winddir":167,"windspeedmph":0.2,"windgustmph":1.1,"maxdailygust":9.2,"hourlyrainin":0,"eventrainin":0,"dailyrainin":0,"weeklyrainin":0,"monthlyrainin":0.571,"totalrainin":1.823,"solarradiation":832.38,"uv":8,"feelsLike":90.84,"dewPoint":70.96,"feelsLikein":73.5,"dewPointin":51,"tz":"America/Chicago","date":"2020-07-20T15:28:00.000Z"},"info":{"name":"My Weather Station","coords":{"coords":{"lon":134.65635809999999,"lat":32.6587316},"address":"100 Park Lane, Yourtown, TN 77777, USA","location":"Yourtown","elevation":146.7066497802734,"geo":{"type":"Point","coordinates":[134.65635809999999,32.6587316]}}}}]'; $data = json_decode($json, true); $fp = fopen('php://memory', 'w+'); // simulate file access $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data)); $csvArray = []; foreach($iterator as $value) { $csvArray[] = $value; } fputcsv($fp, $csvArray); // Output result rewind($fp); // set filepointer to beginning var_dump(fread($fp, 1024)); // read content (max 1024 bytes) fclose($fp);
Output for 8.4.1 - 8.4.13
Deprecated: fputcsv(): the $escape parameter must be provided as its default value will change in /in/OfK3X on line 15 string(309) "xx:xx:xx:xx:xx:xx,1595258880000,74.3,44,29.929,29.235,85.5,1,62,167,0.2,1.1,9.2,0,0,0,0,0.571,1.823,832.38,8,90.84,70.96,73.5,51,America/Chicago,2020-07-20T15:28:00.000Z,"My Weather Station",134.6563581,32.6587316,"100 Park Lane, Yourtown, TN 77777, USA",Yourtown,146.70664978027,Point,134.6563581,32.6587316 "
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26
string(309) "xx:xx:xx:xx:xx:xx,1595258880000,74.3,44,29.929,29.235,85.5,1,62,167,0.2,1.1,9.2,0,0,0,0,0.571,1.823,832.38,8,90.84,70.96,73.5,51,America/Chicago,2020-07-20T15:28:00.000Z,"My Weather Station",134.6563581,32.6587316,"100 Park Lane, Yourtown, TN 77777, USA",Yourtown,146.70664978027,Point,134.6563581,32.6587316 "

preferences:
128.63 ms | 409 KiB | 5 Q