How can PHP be used to create interactive web applications for educational purposes?
PHP can be used to create interactive web applications for educational purposes by incorporating features such as quizzes, interactive lessons, progress tracking, and user feedback. By utilizing PHP alongside HTML, CSS, and JavaScript, developers can create dynamic and engaging educational platforms that cater to different learning styles and objectives.
<?php
// Example PHP code for creating a simple quiz application
// Array of questions and answers
$quiz = array(
"What is the capital of France?" => "Paris",
"What is the largest planet in our solar system?" => "Jupiter",
"Who wrote the play 'Romeo and Juliet'?" => "William Shakespeare"
);
// Check if form submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$score = 0;
// Check each answer
foreach ($quiz as $question => $answer) {
if ($_POST[$question] == $answer) {
$score++;
}
}
// Display score
echo "You scored: " . $score . "/" . count($quiz);
}
?>
<form method="post">
<?php foreach ($quiz as $question => $answer) : ?>
<p><?php echo $question; ?></p>
<input type="text" name="<?php echo $question; ?>">
<?php endforeach; ?>
<button type="submit">Submit</button>
</form>