What are the drawbacks of the current approach in handling language switching in PHP?

The current approach in handling language switching in PHP often involves using conditional statements or functions to determine the language to display. This can lead to cluttered code and make it difficult to manage multiple languages effectively. A better approach would be to use language files or arrays to store all the language strings and switch between them based on a user's preference.

// Define language files
$english = array(
    "hello" => "Hello",
    "goodbye" => "Goodbye"
);

$french = array(
    "hello" => "Bonjour",
    "goodbye" => "Au revoir"
);

// Set default language
$language = $english;

// Switch language
if ($userLanguagePreference == "french") {
    $language = $french;
}

// Display language strings
echo $language["hello"]; // Outputs the appropriate greeting based on language