Export data to a csv file

 
<?php

$csv_data = array();
$csv_data[] = array(
    'col 1',
    'col 2',
    'col 3',
);
$csv_data[] = array(
    'data 1',
    'data 2',
    'data 3',
);
$csv_data[] = array(
    'data 1',
    'data 2',
    'data 3',
);

$fp = fopen('file.csv', 'w');

foreach ($csv_data as $fields) {
    fputcsv($fp, $fields);
}

fclose($fp);

?>

 

Related Snippets

•  Export/Download data as a csv file
•  File Upload Form