What is the purpose of the unlink() function in PHP and how is it used for deleting files?

The unlink() function in PHP is used to delete files from the server. It takes the file path as an argument and removes the file from the filesystem.

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

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