What are some common approaches to creating a navigation bar in PHP for a website?

Creating a navigation bar in PHP for a website involves generating HTML code dynamically based on the current page or user role. One common approach is to use an array to store the navigation items and loop through them to generate the navigation bar.

<?php
// Define navigation items
$navItems = array(
    'Home' => 'index.php',
    'About' => 'about.php',
    'Services' => 'services.php',
    'Contact' => 'contact.php'
);

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