How can PHP handle dynamic content inclusion based on user input, such as switching between different pages or sections?

To handle dynamic content inclusion based on user input in PHP, you can use a combination of conditional statements and include functions. By checking the user input, you can determine which page or section to include dynamically. This allows you to switch between different content based on user choices.

<?php
// Assuming user input is stored in a variable called $page
if(isset($_GET['page'])) {
    $page = $_GET['page'];
    switch($page) {
        case 'home':
            include 'home.php';
            break;
        case 'about':
            include 'about.php';
            break;
        default:
            include 'error.php';
    }
} else {
    include 'home.php'; // Default page to include
}
?>