How can the PHP script be improved to ensure that multiple files can be deleted successfully?

The issue with the current PHP script is that it only attempts to delete one file at a time, which may fail if multiple files need to be deleted. To ensure that multiple files can be deleted successfully, the script can be modified to loop through an array of file paths and delete each file individually.

<?php
$files = array("file1.txt", "file2.txt", "file3.txt");

foreach ($files as $file) {
    if (file_exists($file)) {
        if (unlink($file)) {
            echo "File $file deleted successfully.<br>";
        } else {
            echo "Error deleting file $file.<br>";
        }
    } else {
        echo "File $file does not exist.<br>";
    }
}
?>