A separation values manipulation library
composer require theroadbunch/csv-machine
<?php
// create a new Writer object
$csv = new \RoadBunch\Csv\Writer();
// set the header
$csv->setHeader([ 'Column A', 'Column B' ]);
// add some rows
$csv->addRow([ 'data_one_a', 'data_one_b' ]);
$csv->addRow([ 'data_two_a', 'data_two_b' ]);
// save the CSV to a file
$csv->saveToFile('/path/to/filename.csv');
// write the csv to a string
echo $csv->writeToString();