How can a dynamic menu bar with submenus be created using PHP?

To create a dynamic menu bar with submenus using PHP, you can use an array to store the menu items and their corresponding submenus. Then, you can iterate over the array to generate the HTML code for the menu bar. By dynamically generating the menu items based on the array data, you can easily add, remove, or modify menu items without having to manually update the HTML code.

<?php
$menuItems = array(
    "Home" => array(),
    "About" => array(
        "Our Team",
        "Mission",
        "History"
    ),
    "Services" => array(
        "Web Development",
        "Graphic Design",
        "Digital Marketing"
    ),
    "Contact" => array()
);

echo '<ul>';
foreach($menuItems as $menuItem => $subMenuItems) {
    echo '<li>'.$menuItem;
    if(!empty($subMenuItems)) {
        echo '<ul>';
        foreach($subMenuItems as $subMenuItem) {
            echo '<li>'.$subMenuItem.'</li>';
        }
        echo '</ul>';
    }
    echo '</li>';
}
echo '</ul>';
?>