Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from ii-webworks/patch-2
Browse files Browse the repository at this point in the history
bugfix: first line of csv was omitted
  • Loading branch information
Anton Dachauer committed Sep 3, 2018
2 parents 9cb9657 + cbc59f1 commit 4a6cbd7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions Lib/createCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,19 @@ class createCSV
public function arrayToCsv(array $lines, $delimiter = ';', $enclosure = '"')
{
$csvStr = '';

$count = 0;
foreach ($lines as $line) {
if ($count == 0) {
if ( strlen( $csvStr ) < 1 ) {
$cellNames = array_keys($line);
foreach ($cellNames as $name) {
$csvStr .= $enclosure . $name . $enclosure . $delimiter;
}
$csvStr .= "\n\r";
} else {
foreach ($line as $cell) {
$csvStr .= $enclosure . $cell . $enclosure . $delimiter;
}
$csvStr .= "\n\r";
}
$count++;

foreach ($line as $cell) {
$csvStr .= $enclosure . $cell . $enclosure . $delimiter;
}
$csvStr .= "\n\r";
}

return $csvStr;
Expand Down

0 comments on commit 4a6cbd7

Please sign in to comment.