title: Send array keys and values to csv using php
body: <p>So I am needing all my array keys to be the first column(Column 0) in an excel spreadsheet and the values of the array will be used to fill in the rest of the columns of the csv file (Columns 1-5).</p>
  
  <p>See below examples</p>
  
  <p>Code:</p>
  
  <pre><code>        $array = array();
  
          foreach($k["Time)"] as $key =&gt; $value)
          {
              $array[] = [$value];                  
          }
  
          print_r($array);
  
  
          $file = fopen('demosaved.csv', 'w');
  
  
  
  
          fputcsv($file, array('Column 0','Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5'));
  
  
          $data = array_values($array);
  
          foreach ($data as $row)
          {
            fputcsv($file, $row);
          }
  
          fclose($file);
  </code></pre>
  
  <p>I have also tried the below and receive this error, "Array to string conversion":</p>
  
  <pre><code>        foreach($k["Time Series (1min)"] as $key =&gt; $value)
          {
              $array[] = [$key, $value];
          }
  
  
          var_dump($array);
  
  
          $file = fopen('demosaved.csv', 'w');
  
  
  
  
          fputcsv($file, array('Column 0','Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5'));
  
  
          $data = $array;
  
  
          foreach ($data as $row)
          {
            fputcsv($file, $row);
          }
  
          fclose($file);
  </code></pre>