Are there any best practices for organizing and displaying sub-links in a PHP navigation system?

When organizing and displaying sub-links in a PHP navigation system, it is best to use a multidimensional array to store the links and their corresponding sub-links. This allows for easy management and display of the navigation menu with nested sub-links.

<?php
// Define the navigation links and their corresponding sub-links
$navLinks = array(
    "Home" => "#",
    "About" => "#",
    "Services" => array(
        "Web Development" => "#",
        "Mobile App Development" => "#",
        "SEO" => "#"
    ),
    "Contact" => "#"
);

// Display the navigation menu with sub-links
echo "<ul>";
foreach ($navLinks as $key => $value) {
    echo "<li><a href='$value'>$key</a>";
    if (is_array($value)) {
        echo "<ul>";
        foreach ($value as $subKey => $subValue) {
            echo "<li><a href='$subValue'>$subKey</a></li>";
        }
        echo "</ul>";
    }
    echo "</li>";
}
echo "</ul>";
?>