I am trying to merge several CSV files together in PHP. I already have them merged as whole files using PHP thanks to the thread here (Combining 2 CSV files), however I am looking to merge the files together by individual line.
I would like to read line 1 from CSV 1
, line 1 from CSV 2
, and so forth, then proceed to line 2, 3, etc.
- Cycling between the files in the array with each loop. I have not worked with parsing files in PHP much, so I'm not sure where to begin to accomplish this.
This is what I am trying to accomplish, in case the above was not clear:
CSV1 - Line 1
CSV2 - Line 1
CSV3 - Line 1
CSV1 - Line 2
CSV2 - Line 2
CSV3 - Line 2
CSV1 - Line 3
CSV2 - Line 3
CSV3 - Line 3
.... And continue to loop until there are no lines left in the CSV files.
Try this php code (gets the lines with
file()
).: