What are some potential issues with marking only top-level menu items as active in PHP navigation?

Potential issues with marking only top-level menu items as active in PHP navigation include the inability to highlight sub-menu items when their parent menu item is active. To solve this issue, you can modify the navigation logic to check if the current page URL matches any of the sub-menu items as well.

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

$menu_items = array(
    'Home' => 'index.php',
    'About' => 'about.php',
    'Services' => array(
        'Web Design' => 'web-design.php',
        'SEO' => 'seo.php'
    ),
    'Contact' => 'contact.php'
);

foreach ($menu_items as $key => $value) {
    if (is_array($value)) {
        foreach ($value as $sub_key => $sub_value) {
            if ($current_page == $sub_value) {
                echo '<li class="active"><a href="' . $sub_value . '">' . $sub_key . '</a></li>';
            } else {
                echo '<li><a href="' . $sub_value . '">' . $sub_key . '</a></li>';
            }
        }
    } else {
        if ($current_page == $value) {
            echo '<li class="active"><a href="' . $value . '">' . $key . '</a></li>';
        } else {
            echo '<li><a href="' . $value . '">' . $key . '</a></li>';
        }
    }
}
?>