Compare contents of 2 csv Files in PHP

后端 未结 3 982
被撕碎了的回忆
被撕碎了的回忆 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:24

    I think this is the actual code of which Lord Vader speaks:

    #!/usr/bin/php
     $strLineData) {
        $arrLineData = explode(',',$strLineData);
      }
      return $arrLineData;
    }
    
    $arrFile1 = parseData($strFile1);
    $arrFile2 = parseData($strFile2);
    
    $intRow = 0;
    foreach($arrFile1 as $intKey => $strVal) {
      if(!isset($arrFile2[$intKey]) || ($arrFile2[$intKey] != $strVal)) {
        exit("Column $intKey, row $intRow of $strFile1 doesn't match\n");
      }
      $intRow++;
    }
    print "All rows match fine.\n";
    
    ?>
    

提交回复
热议问题