The following is a working code-example. It validated the input and as you can see, input validation is a a large part of any script.
// configuration
$qsValidKeys = ['q1' => 0, 'q2' => 0, 'q3' => 0, 'q4' => 0];
$qValidValues = ['a', 'b', 'c', 'd'];
// input
$qsGet = array_intersect_key($_GET, $qsValidKeys);
if (!$qsGet) {
trigger_error('No input given.');
return;
}
$qsFiltered = [];
foreach ($qsGet as $key => $value) {
if (in_array($value, $qValidValues, true)) {
$qsFiltered[$key] = $value;
} else {
trigger_error(sprintf('Invalid Input value for "%s".', $key));
}
}
if (!$qsFiltered) {
trigger_error('No input given (filtered).');
return;
}
// processing
$count = array_count_values($qsFiltered);
arsort($count);
$topAnswer = array_keys($count)[0];
$location = sprintf("http://www.mostly-%s.co.uk", $topAnswer);