php - writing array to csv returns blank csv file -


i have array called $content rows has data

$content[0]=name,title,city,country $content[1]=name1,title1,city1,country1 

how save array csv file name on column, title , on?

to write external file code is

$file = fopen("d:/data.csv","w");  foreach ($list $line) {     fputcsv($file,explode(',',$content)); }  fclose($file); 

but has empty rows , columns.

you've got variables mixed up. should be:

foreach ($content $line) {     fputcsv($file, explode(',', $line)); } 

but since $line comma-separated string, don't need explode , use fputcsv(), can write is.

file_put_contents("d:/data.csv", implode(php_eol, $content) . php_eol);