I want to combine two large CSV files with PHP. These files are too large to be inserted into memory immediately. In pseudo code, I can come up with something like this:
for i in file1
file3.write(file1.line(i) + ',' + file2.line(i))
end
But when I iterate over a file with fgetcsv, it is not entirely clear how I will take a line nfrom a specific file without first loading everything into memory.
Any ideas?
Edit: I forgot to mention that each of the two files has the same number of lines, and they are one-to-one. That is, line 62, 322 in file1 goes with line 62, 322 in file2.
source
share