How can PHP be used to dynamically highlight the current page in a menu with over 100 subpages?

To dynamically highlight the current page in a menu with over 100 subpages, you can use PHP to check the current page URL against the menu item URLs and add a CSS class to the active menu item. This can be done by looping through the menu items and comparing the URLs.

<?php
$current_url = $_SERVER['REQUEST_URI'];
$menu_items = array(
    'Home' => '/',
    'About' => '/about',
    'Services' => '/services',
    // Add more menu items as needed
);

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