What function in PHP can be used to list the contents of a directory and how can this be utilized to display language options in a dropdown menu?

To list the contents of a directory in PHP, you can use the `scandir()` function. This function returns an array of files and directories in the specified path. To display language options in a dropdown menu, you can scan a directory containing language files and populate the dropdown menu with the available languages.

$language_dir = 'languages/';
$languages = scandir($language_dir);

echo '<select name="language">';
foreach ($languages as $language) {
    if ($language != '.' && $language != '..') {
        echo '<option value="' . $language . '">' . ucfirst(str_replace('.txt', '', $language)) . '</option>';
    }
}
echo '</select>';