Need help I have 2 csv files
january.csv
with 3 columns:
02Jan2020 Marilyn 31570.29
02Jan2020 Nancy 30000.00
06Jan2020 John 1570.29
06Jan2020 Nancy 5000.00
10Jan2020 Marilyn 570.29
10Jan2020 Nancy 10000.00
.... etc
suppliers.csv
Marilyn
John
Nancy
..etc
Now I want to sum all values in amount (january.csv
) that match from suppliers.csv
Nancy 30000.00
Nancy 5000.00
Nancy 10000.00
echo sum 45000.00
I got to start of with this after researching but not sure if the compare is right and how to sum return values
$filename="january.csv";
$base="suppliers.csv";
$NOWcodes = array();
$file = fopen($base, 'r'); //registred opened
while (($line = fgetcsv($file)) !== FALSE) { array_push($NOWcodes, $line[0]); }
fclose($file);
$file = fopen($filename, 'r'); //all nomes
while (($line = fgetcsv($file)) !== FALSE) {
if(!in_array($line[0],$NOWcodes)){ } //Not sure how to do it here
echo array_sum($sum)."\n";
fclose($file);