Compare two .csv files of different sizes

$file1 = readCSV($current_csv); $file2 = readCSV($previous_csv); $differences = []; $maxLines = max(count($file1), count($file2)); for ($i = 0; $i < $maxLines; $i++) { if ($i < count($file1) && $i < count($file2)) { if ($file1[$i] !== $file2[$i]) { $differences[] = [ 'line_number' => $i + 1, 'file1' => $file1[$i], 'file2' => $file2[$i] ]; // write out here } } elseif ($i < count($file1)) { $differences[] = [ 'line_number' => $i + 1, 'file1' => $file1[$i], 'file2' => null ]; // write out here } elseif ($i < count($file2)) { $differences[] = [ 'line_number' => $i + 1, 'file1' => null, 'file2' => $file2[$i] ]; // write out here } }