How can PHP_SELF be effectively utilized in the context of menu development in PHP?

When developing a menu in PHP, using the PHP_SELF variable can help in creating dynamic menu links that point to the current page. This can be useful for highlighting the current page in the menu or for dynamically generating menu items based on the current page.

<?php
$current_page = basename($_SERVER['PHP_SELF']);
$menu_items = array(
    'Home' => 'index.php',
    'About' => 'about.php',
    'Services' => 'services.php',
    'Contact' => 'contact.php'
);

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