How can the unlink function be used effectively to delete a specific file in PHP, and what are the differences between using a hardcoded file name versus a variable?

To delete a specific file in PHP using the unlink function, you can pass the file path as a parameter to the unlink function. It is important to ensure that the file path is correct and that the file has the necessary permissions to be deleted. When using a hardcoded file name, the file will always be deleted when the script is run. However, when using a variable, you need to ensure that the variable contains the correct file path before passing it to the unlink function.

// Hardcoded file name
$fileToDelete = "example.txt";
unlink($fileToDelete);

// Using a variable
$filePath = "example.txt";
unlink($filePath);