What are some common methods for creating a navigation menu in PHP, such as retrieving data from a database or using a class?

One common method for creating a navigation menu in PHP is to retrieve menu items from a database table. This allows for easy management and updating of the menu items without changing the code. Another method is to use a class to define the menu structure and generate the HTML output dynamically.

// Retrieving menu items from a database
$menuItems = [
    ['title' => 'Home', 'url' => 'index.php'],
    ['title' => 'About Us', 'url' => 'about.php'],
    ['title' => 'Services', 'url' => 'services.php'],
    ['title' => 'Contact Us', 'url' => 'contact.php']
];

// Outputting the navigation menu
echo '<ul>';
foreach ($menuItems as $item) {
    echo '<li><a href="' . $item['url'] . '">' . $item['title'] . '</a></li>';
}
echo '</ul>';