title: Why is fputcsv producing duplicate columns?
body: <p>I am adding a download button to a WordPress site that will query our database, and offer up the result as a CSV. </p>
  
  <p>Everything works, <strong>except the CSV produced has a duplicate column for each column it returns.</strong> </p>
  
  <p>We have checked the SQL query and it does not have duplicates. </p>
  
  <p>Here's how we are generating the CSV:</p>
  
  <pre><code>$rows = //Call to SQL query function
  $fp = fopen('php://output', 'w');
  fputcsv($fp, array_keys($rows));
  
  foreach ($rows as $row) {
    fputcsv($fp, $row);
  }
  
  $filename = "EventResults.csv";
  header('Content-Type: text/csv');
  header("Content-Transfer-Encoding: Binary"); 
  header("Content-disposition: attachment; filename=$filename");
  </code></pre>
  
  <p>We turn the SQL return into a PHP array like this:</p>
  
  <pre><code> $sql = "SELECT * FROM TABLE";
   $statement = $this-&gt;db-&gt;prepare($sql);
   $statement-&gt;execute();
   return $statement-&gt;fetchAll();
  </code></pre>
  
  <p>The results look like this:</p>
  
  <pre><code>Lance,Lance,Armstrong,Armstrong,DEX,DEX,70,70,1,1,60,60,SEC,SEC,"10; 20; 30; 40","10; 20; 30; 40"
  </code></pre>
  
  <p>When they should look like this:</p>
  
  <pre><code>Lance,Armstrong,DEX,70,1,60,SEC,"10; 20; 30; 40"
  </code></pre>
  
  <p>What is causing the duplicates, and how can we get rid of them?</p>