Note that there are some explanatory texts on larger screens.

plurals
  1. POComparing multiple very large csv files against each other
    primarykey
    data
    text
    <p>I have n csv files which I need to compare against each other and modify them afterwards. The Problem is that each csv file has around 800.000 lines.</p> <p>To read the csv file I use <em>fgetcsv</em> and it works good. Get some memory pikes but in the end it is fast enough. But if I try to compare the array against each other it takes ages.</p> <p>One other Problem is that I have to use a foreach to get the csv data with fgetcsv because of the n amount of files. I end up with one ultra big array and can't compare it with array_diff. So i need to compare it with nested foreach loops and that take ages.</p> <p>a code snippet for better understanding:</p> <pre><code>foreach( $files as $value ) { $data[] = $csv-&gt;read( $value['path'] ); } </code></pre> <p>my csv class use fgetcsv to add the output to the array:</p> <pre><code>fgetcsv( $this-&gt;_fh, $this-&gt;_lengthToRead, $this-&gt;_delimiter, $this-&gt;_enclosure ) </code></pre> <p>Every data of all the csv files are stored in the $data array. This is probably the first big mistake to use only one array, but I have no clue how to stay flexible with the files without to use an foreach. I tried to use flexible variable names but I stucked there as well :)</p> <p>Now I have this big array. Normally if I try to compare the values against each other and to find out if the data from file one exists in file two and so on, I use array_diff or array_intersect. But in this case I have only this one big array. And as I said, to run an foreach over it takes ages.</p> <p>Also after only 3 files I have an array with 3 * 800.000 entries. I guess latest after 10 files my memory will explode.</p> <p>So is there any better way to use PHP to compare n amount of very large csv files?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload