Renders CSV from associative array

Sets correct content type and outputs CSV data to browser from array.

php
fork add to bundle source
function output_csv( $array ) { header("Content-type: text/csv"); ob_start(); $df = fopen("php://output", 'w'); fputcsv($df, array_keys(reset($array))); foreach ($array as $row) { fputcsv($df, $row); } fclose($df); echo ob_get_clean(); }

usage

load_function('output_csv'); $array = [ ['name' => 'John', 'age' => 34], ['name' => 'Stefany', 'age' => 27], ]; output_csv($array); // name,age // John,34 // Stefany,27
← how to use this in app?
create log ...inout