What are the potential pitfalls of mixing PHP with HTML when designing a navigation bar?

Mixing PHP with HTML in a navigation bar can lead to messy and hard-to-maintain code. To solve this issue, it's better to separate the PHP logic from the HTML markup by using PHP to dynamically generate the navigation bar content. This approach allows for easier updates and modifications to the navigation bar without having to sift through a mix of PHP and HTML code.

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

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