How can the switch statement in PHP be used to streamline the process of marking active links in a navigation bar?

When creating a navigation bar in PHP, it can be tedious to manually mark active links based on the current page. One way to streamline this process is by using a switch statement to check the current page and apply an "active" class to the corresponding link in the navigation bar. This can help improve code readability and make it easier to manage the active state of links.

<?php
$current_page = basename($_SERVER['REQUEST_URI']);

switch ($current_page) {
    case 'index.php':
        $index_active = 'active';
        break;
    case 'about.php':
        $about_active = 'active';
        break;
    case 'services.php':
        $services_active = 'active';
        break;
    case 'contact.php':
        $contact_active = 'active';
        break;
    default:
        $index_active = 'active'; // Set default active link
}

?>

<ul>
    <li class="<?php echo $index_active; ?>"><a href="index.php">Home</a></li>
    <li class="<?php echo $about_active; ?>"><a href="about.php">About</a></li>
    <li class="<?php echo $services_active; ?>"><a href="services.php">Services</a></li>
    <li class="<?php echo $contact_active; ?>"><a href="contact.php">Contact</a></li>
</ul>