Document toolboxDocument toolbox

Building CSV Data

arrayToCsv

string arrayToCsv(array $data, string $delimiter = ',', string $enclosure = '"')

Parameters

$data: An array of values to convert to CSV

$delimiter: The character that is used to separate the values. The default is ','

$enclosure: Character used to encapsulate the data when the data contains the delimiter. The default is '“'

Return Values

Returns a string of delimited data or false on failure.

Example

/* Create this CSV data from an Array a,b,c,1,2,3 d,e,f,4,5,6 */ $array = [ ['a', 'b', 'c', 1, 2, 3], ['d', 'e', 'f', 4, 5, 6] ]; $csv = $this->arrayToCsv($array);