Are there best practices for organizing PHP code to handle navigation elements efficiently?

When handling navigation elements in PHP, it is best practice to separate the navigation logic from the presentation layer for better organization and maintainability. One way to efficiently handle navigation elements is by creating a separate PHP file or function that generates the navigation menu dynamically based on certain criteria such as user roles or permissions.

// navigation.php

function generateNavigation() {
    // Logic to determine which navigation elements to display
    $navItems = [
        'Home' => 'index.php',
        'About' => 'about.php',
        'Services' => 'services.php',
        'Contact' => 'contact.php'
    ];

    // Generate the navigation menu
    echo '<ul>';
    foreach ($navItems as $label => $url) {
        echo '<li><a href="' . $url . '">' . $label . '</a></li>';
    }
    echo '</ul>';
}

// In your HTML template file
include 'navigation.php';
generateNavigation();