title: Add heading on export using fputcsv php
body: <p>I am trying to export db rows using fputcsv() in csv file. how i can add heading on first, center align then columns then data my code works well without heading. I know there is many api's but is this possible with in my code.</p>
  <p>Here is my code:-</p>
  <pre><code>                      Enquiry Report
  
     id         name         class         func
      1          rk           ba            call()
      2          bk           bd            that()
  
  function exportdata_to_excel($details) {
   
    // filename for download 
    $filename = date(&quot;Y-m-d&quot;).&quot;.csv&quot;;
    header('Content-Type: text/csv');
    header(&quot;Content-Disposition: attachment; filename=\&quot;$filename\&quot;&quot;); 
    $out = fopen(&quot;php://output&quot;, 'w'); 
    
    $flag = false;
   
     //$result = $orderDetails; 
    while($row = mysql_fetch_assoc($details)) {
       $arr =array('Enquiry id'=&gt;$row['id'],'Date'=&gt;$row['created_on'],'Name'=&gt;$row['name'], 'Email'=&gt;$row['email'], 'Telephone'=&gt;$row['telephone'], 'Customer Request'=&gt;$row['customer_request'], 'Special Request'=&gt;$row['special_request']);
      
       if(!$flag) { 
         // display field/column names as first row 
         fputcsv($out, array_keys($arr), ',', '&quot;');
         $flag = true; 
       } 
       
       fputcsv($out, array_values($arr), ',', '&quot;'); 
     } 
     
      fclose($out); 
      exit();
  }
  </code></pre>