70) $score_sum += $score; else $score_sum -= 10; } } if ($score_sum > $max_score) { $max_score = $score_sum; $match_lga = $lga; } } $max_score = 0; foreach ($match_lga['wardNames'] as $ward) { similar_text($ward, $candidate['Ward'], $score); if ($score > $max_score) { $max_score = $score; $match_ward = $ward; } } $candidate['match_lga'] = $match_lga['slug']; $candidate['match_ward'] = $match_ward; } /* Get picture */ foreach ($candidate_data as &$candidate) { $candidate['match_picture'] = ""; } $header = ["Ward", "Candidate Name", "Rating", "Picture"]; /* Generate candidates-generic.csv */ foreach ($lga_list as $lga) { $lga_candidates = array_filter($candidate_data, function ($candidate) use ($lga) { return $candidate['match_lga'] === $lga['slug']; }); if (count($lga_candidates) === 0) continue; $output_file = dirname($lga['config-file'])."/candidates-generic.csv"; if (($handle = fopen($output_file, "w")) === FALSE) { error_log('Error opening output file'); exit(1); } if (fputcsv($handle, $header) === FALSE) { error_log('Error writing headers to output file'); exit(3); } foreach ($lga_candidates as $candidate) { $fields = [ $candidate['match_ward'], $candidate['Name'], $candidate['Score'], $candidate['match_picture'], ]; if (fputcsv($handle, $fields) === FALSE) { error_log('Error writing candidate to output file'); exit(3); } } } exit(0);