How can the script be modified to correctly display active links for submenus in PHP?

The script can be modified by adding a conditional statement to check if the current page matches the link of the submenu. If it does, the active class should be added to the link to indicate that it is the active page. This can be achieved by comparing the current page URL with the submenu link URL and adding the active class accordingly.

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

$submenus = array(
    'Home' => '/',
    'About' => '/about',
    'Services' => '/services',
    'Contact' => '/contact'
);

foreach ($submenus as $title => $url) {
    $class = ($current_page == $url) ? 'active' : '';
    echo '<a href="' . $url . '" class="' . $class . '">' . $title . '</a>';
}
?>