The php multi-choice question scoring algorithm is used to provide guidance on multiple choice questions. The three-point principle is: give 2 points less, do not give a score for multiple choices, and choose not to give a score if: The correct answer 123 submit the answer & nbsp; 123 & nbsp; scored 3 points & nbsp; answers submitted & nbsp; 1234,234, 23, all scored 2 points & nbsp; answers submitted & nbsp;, 1 php multi-choice question scoring algorithm for guidance
Multiple choice questions, one question, three points
The principle is: 2 points for less selection, no points for more selection, and no points for the selection
Suppose: The correct answer is 123
Answers submitted: 123 + 3 points
You can score 2 points for answers 12, 13, and 23.
No score for answers submitted: 1234,234,134,124
There are still better ways to implement PHP Algorithms
------ Solution --------------------
According to your description, your multi-choice questions are not input using checkbox but text.
And there will be no more than 9 alternative answers
Therefore, scores can be written.
Count (array_intersect (str_split ($ correct answer), str_split ($ submit answer ));
That is, split them into arrays, and then take the intersection.
------ Solution --------------------
If you are using checkbox
After submission, an array is obtained, and the intersection with the correct answer array is obtained.
------ Solution --------------------
$ Correct answer = array (1, 2, 3 );
$ Submit answer = array (1, 2 );
$ Score = count (array_intersect ($ correct answer, $ submit answer ));
Echo $ score; // 2
------ Solution --------------------
Reference:
$ Correct answer = array (1, 2, 3 );
$ Submit answer = array (1, 2 );
$ Score = count (array_intersect ($ correct answer, $ submit answer ));
Echo $ score; // 2
The intersection is not in line with the author's question requirements. for example, if the submitted answer is an array (1, 2, 4), then the intersection is (1, 2). actually, it should be 0 points.
------ Solution --------------------
Yes, not exactly.
However, it is unreasonable to choose 1, 2, and 4. Unless 4 is an inverse option, for example: None
In this case, the answer is intentionally misleading.
If you have to write the question like this, you can write it like this.
$ Correct answer = array (1, 2, 3 );
$ Incorrect answer = array (4 );
$ Submit answer = array (1, 2, 4 );
$ Score = array_intersect ($ incorrect answer, $ submit answer )? 0: count (array_intersect ($ correct answer, $ submit answer ));
Echo $ score; // 0
Reference:
Reference: $ correct answer = array (1, 2, 3 );
$ Submit answer = array (1, 2 );
$ Score = count (array_intersect ($ correct answer, $ submit answer ));
Echo $ score; // 2
The intersection is not in line with the author's question requirements. for example, if the submitted answer is an array (1, 2, 4), then the intersection is (1, 2). actually, it should be 0 points.
......
------ Solution --------------------
Just make the merge.
Answer in front, answer in back
Difference set. no score is given.
There is no intersection and no score is given (excluding the blank answer after the previous one. If you confirm that there will be no white-paper answer, you do not need to use it)
No difference set, intersection, number of intersections! = Answer, half a minute
No difference set, intersection exists, number of intersections = answer sheet, full score (this can be done without writing logic and using else directly, because the preceding situations are excluded and the intersection is equal)
Note:
1. the above sequence judgment is performed, because else if incompatible logic is used instead of switch redundancy logic, which saves some judgment conditions.
2. make sure there are no duplicate values for both the answer and answer, otherwise there will be problems in determining the number of intersections
------ Solution --------------------
It can be computed using bitwise operations.
A: 1 B: 2 C: 4 D: 8
How to select AB is 3
How to Select ABCD is 15
For example, if the value is 4, check that the selected result is N to 4.
If (N = 4) 3 points
If 4 & N = N 2 points
Other O points
------ Solution --------------------
Reference:
It can be computed using bitwise operations.
A: 1 B: 2 C: 4 D: 8
How to select AB is 3
How to Select ABCD is 15
For example, if the value is 4, check that the selected result is N to 4.
If (N = 4) 3 points
If 4 & N = N 2 points
Other O points
Bit operations are a good choice. you can select <32 limbs (because the number of system and php versions may be as high as 63), which is very convenient.
But it is not convenient if it is bigger.
------ Solution --------------------
Follow the boss's ideas to do this.
$ Correct = array (1, 2, 3 );
$ Submit = array (1, 2 );
$ Score = count (array_intersect ($ correct, $ submit ));
If ($ score <count ($ submit) {// if you select more than 0 points
$ Score = 0;
}
Echo $ score; // 2