What is the correct way to use the file_exists function with an array of file names in PHP?

When using the file_exists function with an array of file names in PHP, you need to loop through each file name in the array and check if the file exists using the file_exists function. This ensures that you are checking each file individually rather than passing the entire array to the function, which will not work as intended.

$files = ['file1.txt', 'file2.txt', 'file3.txt'];

foreach ($files as $file) {
    if (file_exists($file)) {
        echo "File $file exists.<br>";
    } else {
        echo "File $file does not exist.<br>";
    }
}