Description
Hey,
I just started using the CSVEncoder
and hat some trouble getting it to work with flat data.
The no_headers
flag and its description are very misleading in my opinion.
I wanted to create some simple csv like this:
header1;header2;header3
1;a;x
2;b;y
3;c;z
However from the docs it was really hard to figure out how to specify my custom headers, because of the way the conding handles nested data:
$data = [
[header1, header2, header3]
[1, a, x],
[2, b, y],
[3, c, y]
]
This would not work, because the encoder would automatically set the headers to the surrounding arrays indices [0,1,2].
If I had written this instead:
$data = [
"header1" => [1,2,3],
"header2" => [a,b,c],
...
]
I would get nested headers instead.
So the solution for this would be to set the no_headers => true
flag for the context.
This makes sense if you think about how CSV works, but especially the description "Disables header in the encoded CSV" makes my brain think along the lines "oh, no headers at all" (which of course is nonsense).
I would probably add something along the lines "Disable automatic headers. Use the first data row instead" and maybe add an example, instead.
I can create a PR with an example and suggested documentation if that helps :)