How can PHP be used to create a dynamic quiz with multiple answer options?

To create a dynamic quiz with multiple answer options using PHP, you can store the quiz questions and answers in an array or database. Then, use PHP to generate the quiz interface dynamically by looping through the questions and answer options. You can also use PHP to keep track of the user's answers and calculate the final score.

<?php
// Define an array of quiz questions and answers
$quiz = [
    [
        'question' => 'What is the capital of France?',
        'options' => ['Paris', 'London', 'Berlin', 'Madrid'],
        'correct_answer' => 'Paris'
    ],
    [
        'question' => 'Which planet is known as the Red Planet?',
        'options' => ['Venus', 'Mars', 'Jupiter', 'Saturn'],
        'correct_answer' => 'Mars'
    ],
    // Add more quiz questions as needed
];

// Loop through the quiz array to display questions and answer options
foreach ($quiz as $key => $question) {
    echo '<h3>'.$question['question'].'</h3>';
    foreach ($question['options'] as $option) {
        echo '<input type="radio" name="answer['.$key.']" value="'.$option.'">'.$option.'<br>';
    }
}

// Add a submit button to check answers and calculate the final score
echo '<input type="submit" name="submit" value="Submit Quiz">';
?>