Compare contents of 2 csv Files in PHP

后端 未结 3 959
被撕碎了的回忆
被撕碎了的回忆 2021-01-07 09:35

Does anybody know what is the best way to compare the contents of 2 csv files and report the identical rows.

By identical i mean, records which have the same values

3条回答
  •  天涯浪人
    2021-01-07 10:08

    You have file A and file B.

    Parse file A and create objects for each row and store the content of one row in one object. While you are creating objects, store them in an array.

    Do the same thing for file B.

    So now you have two arrays, first array to store all the data of rows in file A, and another array for B.

    Now you need to iterate through your first array, first each object in array A, scan array B and check if there is a same object in B. if all of the elements in array A passes this. it means they are idential. Otherwise, break.

提交回复
热议问题