What are some methods in PHP to randomly select a filename from a directory and write it to a TXT file?

To randomly select a filename from a directory and write it to a TXT file in PHP, you can use the `scandir()` function to get an array of all filenames in the directory, then use `array_rand()` to select a random filename from the array. Finally, you can write this selected filename to a TXT file using `file_put_contents()`.

$dir = 'path/to/directory';
$files = scandir($dir);
$randomFile = $files[array_rand($files)];

file_put_contents('random_filename.txt', $randomFile);