title: Building CSV with array
body: <p>I need to run a query that will return multiple rows and export it to a CSV. I have to put the cells in a certain order though. </p>
  
  <p>So lets say my table is laid out id, name, address, wife. I need to build a csv in the order of id, address, wife, name. I figured I could just make an array in the correct order and then make a csv with that but after an hour of googling i cant find out how to make a csv with an array. </p>
  
  <p>There is fputcsv but that requires a pre-made csv. Also, i was hoping there was a codeigniter way of doing it. </p>
  
  <pre><code> public function export() {
      $this-&gt;load-&gt;helper('download');
  
      $data[1] = 'i like pie';
      $data[2] = 'i like cake';
      force_download('result.csv', $data);  
  }
  </code></pre>
  
  <p>I tried that but the error said the download helper file was expecting a string not an array. </p>