What are some alternative approaches to displaying multiple menu levels simultaneously in PHP?

When dealing with multiple menu levels in PHP, one alternative approach is to use a nested unordered list structure to display all menu levels simultaneously. This can be achieved by iterating through the menu items and their submenus recursively. By using this method, you can create a visually appealing and user-friendly navigation menu that showcases all menu levels at once.

function displayMenu($menuItems) {
    echo '<ul>';
    foreach ($menuItems as $menuItem) {
        echo '<li>' . $menuItem['label'];
        if (!empty($menuItem['submenu'])) {
            displayMenu($menuItem['submenu']);
        }
        echo '</li>';
    }
    echo '</ul>';
}

// Example usage
$menu = [
    ['label' => 'Home'],
    ['label' => 'About', 'submenu' => [
        ['label' => 'Company'],
        ['label' => 'Team']
    ]],
    ['label' => 'Services', 'submenu' => [
        ['label' => 'Web Design'],
        ['label' => 'SEO']
    ]],
    ['label' => 'Contact']
];

displayMenu($menu);