Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function toCSV(array $data, array $colHeaders = array(), $asString = false) {
- $stream = ($asString)
- ? fopen("php://temp/maxmemory", "w+")
- : fopen("php://output", "w");
- if (!empty($colHeaders)) {
- fputcsv($stream, $colHeaders);
- }
- foreach ($data as $record) {
- fputcsv($stream, $record);
- }
- if ($asString) {
- rewind($stream);
- $returnVal = stream_get_contents($stream);
- fclose($stream);
- return $returnVal;
- }
- else {
- fclose($stream);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement