<?php
class Question
{
public $text; // текст вопроса
public $points = 5; // число баллов, по умолчанию 5
public $answers; // варианты ответов
public $correctAnswer; // правильный ответ
}
$text = "Какая планета располагается четвертой по счету от Солнца?";
$points = 10;
'a' => 'Венера',
'b' => 'Марс',
'c' => 'Юпитер',
'd' => 'Меркурий'
);
$correctAnswer = 'b';
function createQuestions($text, $points, $answers, $correctAnswer)
{
$q = new Question;
$q->text = $text;
$q->points = $points;
$q->answers = $answers;
$q->correctAnswer = $correctAnswer;
$questions[] = $q;
return $questions;
}
function printQuestions($questions)
{
$i = 1; // номер вопроса
foreach ($questions as $question) {
echo "{$i}. {$question->text}\n\n";
echo "Варианты ответов:\n";
foreach ($question->answers as $letter => $answer) {
echo " {$letter}. {$answer}\n";
}
$i++;
}
} {
}
$questions = createQuestions($text, $points, $answers, $correctAnswer);
$text2 = 'Какой город является столицей Великобритании?';
$points2 = 6;
'a' => 'Париж',
'b' => 'Москва',
'c' => 'Нью-Йорк',
'd' => 'Лондон'
);
$correctAnswer2 = 'd';
$questions = createQuestions($text2, $points2, $answers2, $correctAnswer2);
$print = printQuestions($questions);
PD9waHAKCm1iX2ludGVybmFsX2VuY29kaW5nKCJVVEYtOCIpOwoKY2xhc3MgUXVlc3Rpb24KewogICAgcHVibGljICR0ZXh0OyAvLyDRgtC10LrRgdGCINCy0L7Qv9GA0L7RgdCwCiAgICBwdWJsaWMgJHBvaW50cyA9IDU7IC8vINGH0LjRgdC70L4g0LHQsNC70LvQvtCyLCDQv9C+INGD0LzQvtC70YfQsNC90LjRjiA1CiAgICBwdWJsaWMgJGFuc3dlcnM7IC8vINCy0LDRgNC40LDQvdGC0Ysg0L7RgtCy0LXRgtC+0LIKICAgIHB1YmxpYyAkY29ycmVjdEFuc3dlcjsgLy8g0L/RgNCw0LLQuNC70YzQvdGL0Lkg0L7RgtCy0LXRggp9CiR0ZXh0ICAgICAgICAgID0gItCa0LDQutCw0Y8g0L/Qu9Cw0L3QtdGC0LAg0YDQsNGB0L/QvtC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