Junior
What is the difference between unset and unlink functions in PHP?
sobes.tech AI
Answer from AI
unset() — releases a variable, making it undefined.
<?php
$var = 'some value';
unset($var); // The variable $var no longer exists
unlink() — deletes a file from the filesystem.
<?php
$filename = 'path/to/file.txt';
if (file_exists($filename)) {
unlink($filename); // Deletes the file path/to/file.txt
}
Main difference: unset() works with variables inside the PHP script, while unlink() works with files on disk.