I have the following code which exports an array result to csv in PHP:
$file = fopen('php://output', 'w');
$firstLineKeys = false;
foreach ($result as $line) {
if (empty($firstLineKeys))
{
$firstLineKeys = array_keys($line);
fputcsv($file, $firstLineKeys);
$firstLineKeys = array_flip($firstLineKeys);
}
fputcsv($file, $line, ',');
}
fclose($file);
However, i get the last line of the csv file as "Headers Sent" which makes the file a little ugly at the end.
How can I remove that last line or not show the message "Headers Sent"?