I have two csv files, and both have same data structure.
ID - Join_date - Last_Login
I want to compare and get the exactly matching records numbers based on this example:
the first files has 100 records, of which 20 are not included in the 2nd file.
the 2nd file has 120 records.
I want a script in PHP to compare these two files and build two separate CSV files.
And I want to remove all extra records from the 2nd file which are not included in the first file.
And remove all records from the first file which are not included in the 2nd file.
Thanks
There is a GNU utility
comm
that will do this really easily. You couldexec
that through php or just do it directly. If you don't have access tocomm
, the easiest thing to do would be to store both files in an array (probably viafile()
) and usearray_intersect()
.