PHP unset() function
Syntax
unset($variable, $variable, ...);
Parameter | Description |
Variable | One variable (required) |
Definition
It returns true when successfully destroy the given variable.
Usage
unset function is used to destroy or delete one or more variable.
Note:
You can also use unset function to destroy the array variable.
You can use unset function to destroy the object.
Example of unset() function
<?php $Name = 'ptutorial'; echo '
'; echo $Name; unset($Name); ?>
Output
ptutorial
$Name is a string variable that hold the ptutorial and print the variable.
And after use unset the $name variable. You cannot use the variable after unset.
Check variable is unset or not
<?php $Name = 'ptutorial'; var_dump( isset($Name) ); unset($Name); var_dump( isset($Name) ); ?>
Output
bool(true)
bool(false)
Before unset it return true and after unset it return false.