SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to split correct and incorrect answers for certain option types

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

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    my question would be... why? But whatever.

    What type does $dbAnswer have?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •