What are the potential pitfalls of using file_exists within a for loop in PHP?

Using `file_exists` within a for loop in PHP can be inefficient because it performs a file system check on every iteration, which can slow down the script, especially if there are a large number of iterations. To solve this issue, you can perform the file existence check outside of the loop and store the result in a variable, then use that variable within the loop.

$file_path = 'path/to/file.txt';
$file_exists = file_exists($file_path);

for ($i = 0; $i < 10; $i++) {
    if ($file_exists) {
        // File exists, do something
    } else {
        // File does not exist
    }
}