【发布时间】:2020-03-25 12:31:41
【问题描述】:
需要帮助我有 2 个 csv 文件
january.csv 3 列:
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
现在我想将与 suppliers.csv 匹配的所有值 (january.csv) 相加
Nancy 30000.00
Nancy 5000.00
Nancy 10000.00
echo sum 45000.00
我在研究后开始这样做,但不确定比较是否正确以及如何对返回值求和
$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);
【问题讨论】: