Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:create:points [02.04.2015 15:45] oezbf2012en:create:points [23.03.2021 22:47] – [Correct and Incorrect Answers] sophia.schauer
Line 18: Line 18:
 The simplest way of keeping score is for a quiz or a knowledge test. These have a range of selection questions and one of the options is correct for each one.  The simplest way of keeping score is for a quiz or a knowledge test. These have a range of selection questions and one of the options is correct for each one. 
  
-The following PHP code initially defines which questions will be evaluated and what the correct response is. An [[:en:create:array|associative array]] is used accordinglythe variable ID (for selection questions this is the question ID) is used as the key for each entry in the array. Each answer code that will be counted as "correct" is assigned as the value.   +The following PHP code initially defines which questions will be evaluated and what the correct response is. An [[:en:create:array|associative array]] is used accordingly. The arrays are defined here with square brackets (''[]''), the notation with ''array()'' would also be possible. The variable ID (for selection questions this is the question ID) is used as the key for each entry in the array. Each answer code that will be counted as "correct" is assigned as the value.   
  
  
Line 26: Line 26:
 <code php> <code php>
 // Define questions and the correct answers // Define questions and the correct answers
-$questions = array( +$questions = [ 
-  'AB01' => 3),  // correct answer to question AB01 is 3 +  'AB01' => 3,  // correct answer to question AB01 is 3 
-  'AB02' => 1),  // correct answer to AB02 is code 1 +  'AB02' => 1,  // correct answer to AB02 is code 1 
-  'AB03' => 4),  // correct answer to AB03 is hidden behind code 4 +  'AB03' => 4,  // correct answer to AB03 is hidden behind code 4 
-  'AB04' => 2)+  'AB04' => 2, 
-  'AB05' => 1) +  'AB05' => 1 
-  // and so on +  // and so on 
-);+];
  
 // Initialize counter variable // Initialize counter variable
Line 48: Line 48:
 } }
  
-// Show result or otherwise process+// Show result ...
 html('<p>You have scored'.$points.' points.</p>'); html('<p>You have scored'.$points.' points.</p>');
 +// ... or store in an internal variable
 +put('IV01_01', $points);
 </code> </code>
  
en/create/points.txt · Last modified: 30.03.2022 15:28 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki