You might want to try an array of question/answer objects:
Code:
class QuizQuestion {
var $question;
var $answers;
var $right_answer;
var $id;
function QuizQuestion($question, $answers, $right_answer = 0) {
static $id = 0;
$this->id = $id++;
$this->question = $question;
$this->answers = $answers;
$this->right_answer = $right_answer;
}
function to_form_elements() {
ob_start();
?>
<h4><?php echo $this->question; ?></h4>
<ol>
<?php foreach($this->answers as $key => $answer) { ?>
<li>
<label>
<input
name="answer<?php echo $this->id; ?>"
type="radio" value="<?php echo $key; ?>">
<?php echo $answer; ?>
</label>
</li>
<?php } ?>
</ol>
<?php
return ob_get_clean();
}
}
$questions = array(
new QuizQuestion('What is the right answer?',
array('A right answer',
'A wrong answer',
'Another wrong answer')),
new QuizQuestion('Ah, but how about this one?',
array('A wrong answer',
'Another wrong answer',
'A right answer',
'Yet another wrong answer'),
2));
If I were you, I'd then have arrays like that of perhaps fifteen questions per file, or better still, a database. A database would solve most of your data-management problems here.
Bookmarks