Posted By

macodev on 04/07/17


Tagged

array csv excel


Versions (?)

array to csv


 / Published in: PHP
 

transform array into csv format

  1. function array2csv(array &$array)
  2. {
  3. if (count($array) == 0) {
  4. return null;
  5. }
  6. $df = fopen("php://output", 'w');
  7. fputcsv($df, array_keys(reset($array)));
  8. foreach ($array as $row) {
  9. fputcsv($df, $row);
  10. }
  11. fclose($df);
  12.  
  13. return ob_get_clean();
  14. }

Report this snippet  

You need to login to post a comment.