Difference between unset() and unlink() in PHP



In PHP unlink() is a function for file system handling, unlink() is used to delete files (physical). Suppose you have uploaded a file and wants to delete this file through the coding then unlink() function is used to delete the file, Suppose you have an image with the name test.png and you wants to delete this image then use the
<?php
.....Condition........
......................

unlink(image path/test.png);

.....Condition........
......................
?>

or

<?php
$xx = fopen('testing.html', 'a');
fwrite($xx, '<h1>Hello EWA!</h1>');
fclose($xx);

unlink('testing.html');
?>

unset() is a function for variable management. It will make a variable undefined. Or we can say that unset() is used to null out the value of a given variable. OR Unset () is used to destroy a variable in PHP. In can be used to remove a single variable, multiple variables, or an element from an array.

Example for unset() :

<?php
$value = 200;
echo $value; //Out put will be 200
$value1 = unset($value);
echo $value1; //Output will be null
?>

<?php
unset($value);  // remove a single variable
unset($my_array['element']); //remove a single element in an array
unset($value1, $value2, $value3); // remove multiple variables
?>

Hope this will be helpful to someone. Thanks