I have a situation where my headers aren't predefined, so I would like to add columns dynamically as I process the input without having to read all the input before writing.
It makes sense to keep track of just the header as an Array and prepend it at the end, but I'm yet to see an easy way to do this.
I've cut my code down to the minimum to understand how it is currently, pretty standard PHP csv writing. I haven't yet added any code to process the dynamic part of it.
$handle = fopen($this->path, 'w');
fputcsv($handle, ['initial', 'header', 'values']);
foreach($data as $datum){
fputcsv($handle, $datum));
}