What are the advantages and disadvantages of using external links in PHP navigation menus?

When using external links in PHP navigation menus, the main advantage is that it allows you to easily link to external websites or resources. However, a disadvantage is that it may lead users away from your website, potentially decreasing engagement. To mitigate this, you can set external links to open in a new tab or window to keep users on your site while still providing the external resource.

<?php
// Example of a navigation menu with external links opening in a new tab
$menuItems = [
    "Home" => "index.php",
    "About" => "about.php",
    "External Link" => "https://www.externalwebsite.com",
    "Contact" => "contact.php",
];

echo "<ul>";
foreach ($menuItems as $title => $link) {
    if (strpos($link, 'http') === 0) {
        echo "<li><a href='$link' target='_blank'>$title</a></li>";
    } else {
        echo "<li><a href='$link'>$title</a></li>";
    }
}
echo "</ul>";
?>