Are there alternative approaches or design patterns in PHP that can be used instead of switch statements for including different pages based on conditions?

Switch statements can become unwieldy and hard to maintain when dealing with multiple conditions for including different pages in PHP. One alternative approach is to use an associative array where keys represent conditions and values represent the corresponding page includes. This can make the code cleaner, more modular, and easier to extend in the future.

// Define an associative array mapping conditions to page includes
$pageIncludes = [
    'condition1' => 'page1.php',
    'condition2' => 'page2.php',
    'condition3' => 'page3.php',
    // Add more conditions and page includes as needed
];

// Check the condition and include the corresponding page
$condition = 'condition2'; // Example condition
if (array_key_exists($condition, $pageIncludes)) {
    include $pageIncludes[$condition];
} else {
    include 'defaultPage.php'; // Include a default page if condition does not match
}