Code below seperate correct letters and incorrect letters from each other if option type is letter. E.g If option type is A-D and correct letter is B, then it removes B from A B C D using the `$wrong` variable making it A C D for `$incorrect_ans` variable.
Now what I want to do is that if option type is `Yes or No` and correct answer is `Yes`, then it should seperate `Yes` from `Yes, No` so that I can display `No` in `incorrect_ans` variable. Problem is that at the moment it is not spilt both these options, so it is displaying bother this answers as incorrect answers when in this example `No` should be incorrect. But how can this be achieved?
I want the same to work for `True or False` option as well. As I mentioned my code works for letter answers, just not `Yes or No` or `True or False`.
Below is code:
PHP Code:$specialOptionTypes = array('Yes or No' => array( 'Yes', 'No' ),'True or False' => array( 'True', 'False' ));
while ($stmt->fetch()) {
// Do this for each row:
if ( array_key_exists( $dbOptionType, $specialOptionTypes ) ) {
$options = $specialOptionTypes[$dbOptionType];
} else if ( preg_match( '/^([A-Z])-([A-Z])$/', $dbOptionType, $match ) ) {
$options = range( $match[1], $match[2] );
} else {
// issue warning about unrecognized option type
$options = array();
}
$right = $dbAnswer; // $right = 'True';
$wrong = array_diff( $options, $right );
$incorrect_ans[] = $wrong;
}



Reply With Quote

Bookmarks