diff --git a/csv-generic/gen-generic.php b/csv-generic/gen-generic.php index fcbf907..ccc6cca 100644 --- a/csv-generic/gen-generic.php +++ b/csv-generic/gen-generic.php @@ -122,13 +122,17 @@ foreach ($lga_list as $lga) { foreach ($lines as $line_key => $line) { $match_index = array_search($override['Match Field'], $header); $replace_index = array_search($override['Replace Field'], $header); - if ($line[$match_index] === $override['Match Value']) { - $lines[$line_key][$replace_index] = $override['Replace Value']; + if ($line[$match_index] === $override['Match Value']) { + if ($replace_index !== false) + $lines[$line_key][$replace_index] = $override['Replace Value']; + else /* If 'Replace Field' is not matched - delete this entry */ + $lines[$line_key]['Delete'] = 'y'; } } } foreach ($lines as $line) { + if (isset($line['Delete'])) continue; if (fputcsv($handle, $line) === FALSE) { error_log('Error writing candidate to output file'); exit(3);