How can the PHP exit function be used to prevent unwanted output after file downloads?

When downloading files in PHP, unwanted output after the file download can occur due to additional content being sent to the browser. To prevent this, you can use the `exit` function to stop the script execution immediately after sending the file download headers. This ensures that no additional content is sent to the browser after the file download.

// Set the appropriate headers for file download
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.txt"');

// Output the file content
readfile('path/to/example.txt');

// Stop script execution to prevent unwanted output
exit;