What are some best practices for structuring PHP code to efficiently manage multiple pages and subpages within a website?

When managing multiple pages and subpages within a website, it is essential to have a structured approach to organizing your PHP code. One best practice is to use a modular approach by creating separate PHP files for each page or subpage. This helps in maintaining code readability, reusability, and scalability. Additionally, using functions and classes to encapsulate related code can further improve code organization.

// index.php (main page)
<?php
$page = isset($_GET['page']) ? $_GET['page'] : 'home';

switch ($page) {
    case 'home':
        include 'pages/home.php';
        break;
    case 'about':
        include 'pages/about.php';
        break;
    case 'contact':
        include 'pages/contact.php';
        break;
    default:
        include 'pages/error.php';
        break;
}
?>
```

```php
// pages/about.php
<?php
// code for the about page
?>
```

```php
// pages/contact.php
<?php
// code for the contact page
?>