I need to get the difference between two CSV files, whereby the latest file in this case file2.csv overwrites rows with same values with an updated version and removes rows with identical data.
file1.csv
GHI, 0, 0
ABC, 12, 1
DEF, 10, 1
file2.csv
ABC, 8, 1
DEF, 10, 1
GHI, 2, 0
The final CSV should be like this :
ABC, 8, 1
GHI, 2, 0
the php code:
<?php
$file1 = file('file1.csv');
$file2 = file('file2.csv');
sort($file1);
sort($file2);
var_dump($file1);
var_dump($file2);
$diff = array_diff($file2, $file1);
var_dump($diff);
?>
returns this
ABC, 8, 1
DEF, 10, 1
GHI, 2, 0
Now when I change manually file1.csv to this:
ABC, 12, 1
DEF, 10, 1
GHI, 0, 0
it returns this as expected:
ABC, 8, 1
GHI, 2, 0
When I dump the sorted array it seems the sort function works as it returns just like when I change the order manually
ABC, 12, 1
DEF, 10, 1
GHI, 0, 0
Yet it seems not to produce the same end result. Any clues?