What are the advantages of using a switch statement versus an array when including pages dynamically in PHP?

When including pages dynamically in PHP, using a switch statement allows for easy branching based on a specific condition, such as a page identifier. This can make the code easier to read and maintain compared to using an array to map page identifiers to file paths. Additionally, a switch statement is more efficient for a small number of cases compared to searching through an array.

$page = isset($_GET['page']) ? $_GET['page'] : 'home';

switch ($page) {
    case 'home':
        include 'home.php';
        break;
    case 'about':
        include 'about.php';
        break;
    case 'contact':
        include 'contact.php';
        break;
    default:
        include '404.php';
}