Thank you very much gw1500se . I somewhat messed up the question. Actually i want to create a file on CSV format.
Below is my logic to achieve my goal
if($generate_csv){
generateCSV($custom[0]['details'], date('Y_m_d_')."check".".CSV", $detail_headers);
}
function generateCSV($data, $filename) {
$file = fopen("/local/myloc/populated/".$filename,"w+");
$i = 0;
foreach ($data as $line) {
$fields = array();
foreach ($line as $k => $v)
{
$fields[$k] = $v;
}
if( $i === 0 )
{
fputcsv($file, array_keys($fields) ); // First write the headers
}
fputcsv($file, array_values($fields));
$i++;
}
fclose($file);
}
There is no issue in my output
Date,time,Device,lable,throughput_read,throughput_write
11/21/2020,00:00,audigysg36s6101,192905199.0,1742118968.0,11.073020990149,97.584
11/21/2020,00:05,audigysg36s6101,192914200.0,1742253920.0,11.072679922568,97.559
But i need to show every value in double quotes like
"11/21/2020,00:00","audigysg36s6101","192905199.0","1742118968.0","11.073020990149","97.584"
to get above output, i changed my code
$fields[$k] = $v. ' ';
Now i got one blank space in at the end of each value like
"11/21/2020,00:00 ","audigysg36s6101 ","192905199.0 ","1742118968.0 ","11.073020990149 ","97.584 "
If i use trim then it removes all double quotes in the line that i don't need.
11/21/2020,00:00,audigysg36s6101,192905199.0,1742118968.0,11.073020990149,97.584
Input values to get csv
[1] => Array
(
[Date] => 11/21/2020
[time] => 00:00
[Device] => audigysg36s6101
[lable] => 192905199.0
[throughput_read] => 1742118968.0
[throughput_write] => 11.073020990149
)
[1] => Array
(
[Date] => 11/21/2020
[time] => 00:15
[Device] => audigysg36s6101
[lable] => 192914200.0
[throughput_read] => 1742253920.0
[throughput_write] => 11.072679922568
)