How can PHP be used to check if a file exists before attempting to delete it?

To check if a file exists before attempting to delete it in PHP, you can use the `file_exists()` function. This function takes a file path as a parameter and returns true if the file exists and false if it does not. By using this function before attempting to delete a file, you can avoid errors that may occur if the file does not exist.

$file_path = 'path/to/file.txt';

if (file_exists($file_path)) {
    unlink($file_path);
    echo 'File deleted successfully.';
} else {
    echo 'File does not exist.';
}