What are the best practices for structuring navigation menus in PHP to ensure scalability and maintainability?

When structuring navigation menus in PHP, it is important to separate the navigation logic from the presentation layer to ensure scalability and maintainability. One way to achieve this is by using an array to store the menu items and then looping through the array to generate the menu HTML output dynamically.

<?php
$menuItems = [
    'Home' => '/',
    'About' => '/about',
    'Services' => '/services',
    'Contact' => '/contact'
];

function generateMenu($menuItems) {
    $menu = '<ul>';
    foreach ($menuItems as $label => $url) {
        $menu .= '<li><a href="' . $url . '">' . $label . '</a></li>';
    }
    $menu .= '</ul>';
    return $menu;
}

echo generateMenu($menuItems);
?>