Yes indeed there is, you could loop through the $_POST data, which would be a bit more elegant. But for a bit of abstraction, put the code which handles the calculation inside of a function.
This brings up the problem that the answer in the $_POST array does not reflect the score which it represents. There are a few ways around this:
Either put the answer as a string which can reflect both the answer and the score (i.e. in each radio button = <input type="radio" name="answer1" value="1, black">) and then split the answer into an array using ", " as the delimiter. This is OK but a bit messy.
The second way is to assume that the questions are not going to change on a regular basis, and so store the answers somewhere (in a text file or a database) and just put the score in the radio button. Then we can run a simple function (or functions perhaps depending on the form input type) to get the result.
$character1 = 0;
$character2 = 0;
$character3 = 0;
function doAdd($score){
global $character1, $character2, $character3;
switch ($score){
case 1:
++$character1;
case 2:
++$character2;
case 3;
++$character3;
}
}
foreach($_POST as $key => $value){
doAdd($value);
}
Then when generating the final result page, you would need to do a lookup for each score against the database/text file to get the actual answer text.
The above code is untested 🙂