What are the best practices for handling file downloads in a loop in PHP?

When handling file downloads in a loop in PHP, it is important to properly set headers to indicate that the response is a file download. Additionally, you should use output buffering to prevent any output before the file download. To handle multiple file downloads in a loop, you can use a combination of `readfile()` and `ob_clean()` functions to clear the output buffer before each new file download.

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

// Loop through file paths
$files = ['file1.txt', 'file2.txt', 'file3.txt'];
foreach ($files as $file) {
    // Clear output buffer
    ob_clean();
    
    // Output file contents
    readfile($file);
}