Skip to content
PHP Logo

How can the unset() function be used to remove a variable in PHP?

The unset() function in PHP is used to remove a variable from the current scope. This can be useful when you no longer need a variable and want to free up memory. To remove a variable using unset(), simply pass the variable name as an argument to the function.

php
$variable = "This is a variable";
unset($variable);
// $variable is now removed