What are the best practices for handling language-specific navigation in PHP websites without using separate index files?

When handling language-specific navigation in PHP websites without using separate index files, one of the best practices is to utilize URL parameters to determine the language and dynamically load the appropriate content based on the selected language. This can be achieved by creating language-specific arrays or using a database to store language translations and navigation links.

<?php
// Define language-specific navigation links
$navLinks = [
    'en' => [
        'Home' => 'index.php?lang=en',
        'About' => 'about.php?lang=en',
        'Contact' => 'contact.php?lang=en'
    ],
    'fr' => [
        'Accueil' => 'index.php?lang=fr',
        'À propos' => 'about.php?lang=fr',
        'Contact' => 'contact.php?lang=fr'
    ]
];

// Get the selected language from URL parameter or default to English
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'en';

// Display navigation links based on selected language
foreach ($navLinks[$lang] as $label => $url) {
    echo "<a href='$url'>$label</a> ";
}
?>