0

I am trying to export an array to csv, but my csv contains only one row with many fields (columns). I want to achieve to export into rows my data. My data looks like when I dump:

array(2) { [0]=> string(10) "something1" [1]=> string(18) "something2" }

here is the php code: ($names is my array)

$list = array ($names);
$fp = fopen('download.csv', 'w');
    foreach ($list as $fields) {
    fputcsv($fp, $fields);
}
fclose($fp);

Thank you in advance!

EDIT: now looks like: enter image description here how to achieve this:enter image description here

user348246
  • 380
  • 4
  • 16

1 Answers1

2

There's no need to put the $names into an array to accomplish what you want.

$fp = fopen('download.csv', 'w');
foreach ($names as $name) {
    fputcsv($fp, [$name]);
}
fclose($fp);
ebraley
  • 206
  • 1
  • 9