Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9134243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:37:33+00:00 2026-06-17T08:37:33+00:00

Code below separates correct letters and incorrect letters from each other if option type

  • 0

Code below separates 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 separate Yes from Yes, No so that I can display No in incorrect_ans variable. Problem is that at the moment it is not split 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:

$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;
}

UPDATE:

If I had this data in database

Question Table:

QuestionId QuestionNo OptionId
11          1         3
12          2         26

Option_Table Table:

OptionId OptionType
1        A-C
2        A-D
3        A-E

..............

26       Yes or No

Answer Table:

AnswerId Answer QustionId
1        A      11
2        C      11
3        Yes    12

Ok so for Question 1 (look at tables closely), The option type ($OptionType) is A-E meaning by using code below:

(preg_match('/^([A-Z])-([A-Z])$/', $dbOptionType, $match)) {
        $options = range($match[1], $match[2]);

It displays these Options A B C D E.

Now Correct Answers for Question 1 is A and C (using $right = $dbAnswer;). So Split correct answers from incorrect answers using:

$wrong = array_diff($options, $right);

Then we are left with the incorrect answers which as B D E. These are stored in array using:

$incorrect_ans[] = $wrong;

Problem I have is that this does not work for Yes or No option in question 2. The incorrect answer is No and correct answer is Yes for question 2 but it does not split Yes and No as it displays them both as incorrect answers. This is incorrect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:37:34+00:00Added an answer on June 17, 2026 at 8:37 am

    Update your code a bit

    $right = array($dbAnswer); // $right = array('True');
    $incorrect_ans[] = array_diff( $options, $right );  
    

    The array_diff need both param be array. You can also var_dump the $option variable to be sure that it contains the right data.
    Of course, the final $incorrect_ans array can contains both ‘Yes’ and ‘No’ because each is added when you fetch each row. Each element of $incorrect_ans contains the wrong answers of the question it parsed from . I think you should use the question ID as the key ob the $incorrect_ans, not just use the default numerical key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the code below to separate a group of strings separated by a
Code below is used to save PostgreSql database backup from browser in Apache Mono
I'm importing sales data from iTunes successfully using: FasterCSV.parse(uploaded_io, {:headers => true, :col_sep =>\t}).each
Code below is working well as long as I have class ClassSameAssembly in same
The code below simply didn't work. document.getElementById('files').addEventListener('change', handleFileSelect, false); reported by firebug that this
This code below allows me to find the word error in all my files
The code below fails on the line: Class.forName(oracle.jdbc.driver.OracleDriver); with the error: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver The
My code below gave a different length for the unsigned char pointer I expect.
The code below sets a select menu with UI selectmenu by $('.anyclass').selectmenu(); but the
The code below will validate required fields within currently visible fieldsets, but only if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.