Covert array to CSV

Returns CSV string from array. Read more.

php
fork add to bundle source
function array_to_csv($array) { if ( !$array ) return; ob_start(); $df = fopen("php://output", 'w'); fputcsv($df, array_keys(reset($array))); foreach ($array as $row) { fputcsv($df, $row); } fclose($df); return ob_get_clean(); }

usage

load_function('array_to_csv'); $array = [ ['id' => 1, 'name' => 'John' ], ['id' => 20, 'name' => 'Sarah'], ]; echo array_to_csv($array); // id,name // 1,John // 20,Sarah
← how to use this in app?
create log ...inout