<?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 $q;
}
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);
printQuestions($questions);
PD9waHAKCm1iX2ludGVybmFsX2VuY29kaW5nKCJVVEYtOCIpOwoKY2xhc3MgUXVlc3Rpb24KewogICAgcHVibGljICR0ZXh0OyAvLyDRgtC10LrRgdGCINCy0L7Qv9GA0L7RgdCwCiAgICBwdWJsaWMgJHBvaW50cyA9IDU7IC8vINGH0LjRgdC70L4g0LHQsNC70LvQvtCyLCDQv9C+INGD0LzQvtC70YfQsNC90LjRjiA1CiAgICBwdWJsaWMgJGFuc3dlcnM7IC8vINCy0LDRgNC40LDQvdGC0Ysg0L7RgtCy0LXRgtC+0LIKICAgIHB1YmxpYyAkY29ycmVjdEFuc3dlcjsgLy8g0L/RgNCw0LLQuNC70YzQvdGL0Lkg0L7RgtCy0LXRggp9CiR0ZXh0ICAgICAgICAgID0gItCa0LDQutCw0Y8g0L/Qu9Cw0L3QtdGC0LAg0YDQsNGB0L/QvtC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