What potential issue might arise when using the 'unlink' function in PHP to delete files in a loop?
When using the 'unlink' function in a loop to delete files, a potential issue that may arise is that the function might fail to delete a file due to permission restrictions or file locks. To solve this issue, you can check if the file exists before attempting to delete it using the 'file_exists' function.
$files = ['file1.txt', 'file2.txt', 'file3.txt'];
foreach ($files as $file) {
if (file_exists($file)) {
unlink($file);
echo "File $file deleted successfully.\n";
} else {
echo "File $file does not exist.\n";
}
}