fputcsv function in PHP

fputcsv: fputcsv is a inbuilt function of PHP, fputcsv function is used to format a line as CSV
and its writes it in the specified file stream, it needs single dimensional array and target file stream

Example of fputcsv:

<?php

$fcsvArray = array(
    array('Sr', 'Title', 'Desc'),
    array('1', 'Blogshub', 'Well explanation')
);
$csvOutput = fopen('csvfile.csv', 'w');
foreach ($fcsvArray as $values) {
    fputcsv($csvOutput, $values);
}
fclose($csvOutput);

?>

Explanation
It writes the input array in to CSV file and download it.

Keep Learning 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *