Difference between unlink() and unset()

unlink() method

Php unlink() method is used to delete the given file or image from the file system.


<?php
$filename="/fakepath/abc.pdf"; 
unlink($filename);
?>

unset() method

Php unset() method is used to delete the variable. when you unset the variable then variable is deleted and it release the occupied memory by the variable.
unset() method is used to delete the array element and object property also.

Syntax:-


<?php
unset($variable_name);
?>

Example:- Suppose, You have an employee_name variable and you unset this variable and after that print, this variable then shows the Undefined variable: employee_name.


<?php
$employee_name="John";
unset($employee_name);
echo $employee_name;
?>
Notice: Undefined variable: employee_name

Try it Yourself