title: How to write array values into a csv file in PHP?
body: <p>I have an array whose structure is like  <code>$data = array{0=&gt;'abc',1=&gt;xyz,2=&gt;tqs}</code></p>
  
  <p>Now I need to write these values into a csv file. I need to display every value in 1st column and with everytime new row on new insert along with previous value already available.</p>
  
  <p>Below is the code I am using but everytime I execute it I get the last value in the file:</p>
  
  <pre><code>for ($c=0; $c &lt; $num; $c++) {
        echo $data[$c];
     echo  $query = "select prod_sku,prod_name 
      from
        tbl_product
      where 
       prod_sku = '".$data[$c]."'";
       $result = mysql_query($query);
       $row = mysql_fetch_array($result);
       if(empty($row)){
       print_r($row);
       echo 'test';
       $fp = fopen("file.csv", "w");
       print_r($data[0]);
  
        fputcsv($fp, $data[0]);
        fclose($fp);
  
  
    } 
  </code></pre>
  
  <p>How can i achieve this using PHP?</p>