<?php
class Question
{
    public $text;           // текст вопроса
    public $points = 5;     // число баллов, по умолчанию 5
    public $answers;        // варианты ответов
    public $correctAnswer;  // правильный ответ
}
 
// Функция, создающая массив с вопросами:
function createQuestions()
{
    // Создаем пустой массив
    $questions = [];
 
    // Создаем и заполняем первый объект
    $q = new Question;
    $q->text = "Познаю ли Я ООП?";
    $q->points = 1;
    $q->answers = array('a'=>'Да', 'b' => 'Не знаю', 'c' => 'Все зависит от меня самого', 'd' => 'Нет');
    $q->correctAnswer = 'c';
    // Кладем вопрос в массив
    $questions[] = $q;
 
    // Создаем второй объект
    $q = new Question;
    $q->text = "Оп - няша?";
    $q->points = 1337;
    $q->answers = array('a' => 'Да', 'b' => 'Определенно', 'c' => 'Он еще и умняша', 'd' => 'Все ответы верны');
    $q->correctAnswer = 'd';
    // Кладем вопрос в массив
    $questions[] = $q;
 
    // Создаем третий объект
    $q = new Question;
    $q->text = "Какой город является столицей России?";
    $q->points = 100;
    $q->answers = array('a' => 'Киев', 'b' => 'Санкт-Петербург', 'c' => 'Лондон', 'd' => 'Москва');
    $q->correctAnswer = 'd';
    // Кладем вопрос в массив
    $questions[] = $q;
 
    return $questions;
}

function printQuestions($questions)
{
    $number = 1; // номер вопроса

    foreach ($questions as $question) {
        echo "{$number}. {$question->text}\n\n";

        echo "Варианты ответов:\n";

        foreach ($question->answers as $letter => $answer) {
            echo "  {$letter}. {$answer}\n";
        }

        $number++; 
    }
}

$questions = createQuestions();
printQuestions($questions);