What are the potential pitfalls of not structuring PHP code conceptually for a quiz application?

If PHP code for a quiz application is not structured conceptually, it can lead to messy and hard-to-maintain code. This can result in difficulties in adding new features, debugging, and overall code readability. To solve this issue, it is important to follow best practices such as separating concerns, using classes and functions for different functionalities, and organizing code in a logical manner.

// Example of structuring PHP code conceptually for a quiz application

// Define a class for Quiz
class Quiz {
    private $questions = [];

    // Method to add a question to the quiz
    public function addQuestion($question) {
        $this->questions[] = $question;
    }

    // Method to display all questions in the quiz
    public function displayQuestions() {
        foreach ($this->questions as $question) {
            echo $question . "<br>";
        }
    }
}

// Create a new quiz object
$quiz = new Quiz();

// Add questions to the quiz
$quiz->addQuestion("What is the capital of France?");
$quiz->addQuestion("Who wrote 'Romeo and Juliet'?");

// Display all questions in the quiz
$quiz->displayQuestions();