What is the purpose of the unlink function in PHP and what potential issues can arise when using it?

The unlink function in PHP is used to delete a file from the filesystem. One potential issue that can arise when using unlink is that it can permanently delete a file without any confirmation, which can lead to accidental data loss. To prevent this, you can first check if the file exists before calling unlink.

$file = 'example.txt';

if (file_exists($file)) {
    unlink($file);
} else {
    echo "File does not exist.";
}