I'm exporting an array to a csv file, but I'm having trouble with formatting
This is the array:
Array ( [0] => Array ( [id] => 41 [item] => HY87MB [cost] => $43,679 ) [1] => Array ( [id] => 39 [item] => UYITHO [cost] => $79,202.10 ) )
And the csv file looks like this:
41,HY87MB,$43,679
39,UYITHO,$9,202.10
When, I want it to look like this:
41,"HY87MB","$43,679"
39,"UYITHO","$9,202.10"
Here's the code I'm using:
$fp = fopen(testfile.csv', 'w');
foreach($result as $line) {
foreach($line as $line2) {
fputcsv($fp, split(',',$line2));
}
}
fclose($fp);
header('Location: testfile.csv');