How can PHP be used to dynamically switch between different files based on user input?

To dynamically switch between different files based on user input in PHP, you can use a combination of conditional statements and include or require functions. By capturing the user input, you can determine which file to include or require in your PHP script.

<?php
$user_input = $_GET['page']; // Assuming user input is passed through the 'page' parameter in the URL

switch ($user_input) {
    case 'home':
        require 'home.php';
        break;
    case 'about':
        require 'about.php';
        break;
    case 'contact':
        require 'contact.php';
        break;
    default:
        require 'error.php'; // If user input does not match any case
}
?>