What are the potential pitfalls of using a switch statement in a dynamic menu system in PHP?

One potential pitfall of using a switch statement in a dynamic menu system in PHP is that it can become difficult to maintain and scale as the number of menu items grows. To solve this issue, you can use an associative array to map menu items to their corresponding actions or URLs. This approach makes it easier to add, remove, or modify menu items without having to update a switch statement.

$menuItems = [
    'home' => 'index.php',
    'about' => 'about.php',
    'contact' => 'contact.php'
];

if (isset($_GET['page']) && array_key_exists($_GET['page'], $menuItems)) {
    $page = $_GET['page'];
    header("Location: " . $menuItems[$page]);
    exit;
} else {
    // Handle invalid menu items or default behavior
}