How can PHP be leveraged to manage different main content pages (e.g., main1.php, main2.php) based on user selections in a sidebar menu?

To manage different main content pages based on user selections in a sidebar menu, you can use PHP to dynamically include the desired main content page based on the user's selection. This can be achieved by passing a parameter in the URL when a user clicks on a menu item, and then using PHP to include the corresponding main content page based on the parameter value.

<?php
// Check if a page parameter is set in the URL
if(isset($_GET['page'])) {
    // Define an array mapping menu items to main content pages
    $pages = array(
        'main1' => 'main1.php',
        'main2' => 'main2.php'
    );

    // Get the selected page from the URL parameter
    $selectedPage = $_GET['page'];

    // Check if the selected page exists in the array
    if(array_key_exists($selectedPage, $pages)) {
        // Include the corresponding main content page
        include $pages[$selectedPage];
    } else {
        // Handle invalid page selections
        echo "Invalid page selection";
    }
} else {
    // Default main content page to include
    include 'main1.php';
}
?>