How can one efficiently handle multiple subpages within a PHP website without creating individual variables for each page?

When handling multiple subpages within a PHP website, it is efficient to use a single variable to store the page information and dynamically include the corresponding content based on the requested page. This can be achieved by using a switch statement to determine which subpage is being accessed and include the appropriate content file.

<?php
// Get the requested subpage from the URL
$subpage = isset($_GET['subpage']) ? $_GET['subpage'] : 'home';

// Include the corresponding content file based on the subpage
switch ($subpage) {
    case 'about':
        include 'about.php';
        break;
    case 'services':
        include 'services.php';
        break;
    case 'contact':
        include 'contact.php';
        break;
    default:
        include 'home.php';
}
?>