The unset() function is an inbuilt function in PHP which is used to unset a specified variable. The behavior of this function depends on different things. If the function is called from inside of any user defined function then it unsets the value associated with the variables inside it, leaving the value which is initialized outside it.
It means that this function unsets only local variable. If we want to unset the global variable inside the function then we have to use $GLOBALS array to do so.
- $variable: This parameter is required, it is the variable which is needed to be unset
Return Value: This function does not returns any value.
Below programs illustrate the unset() function in PHP:
Before unset:1 After unset:5 Before unset:2 After unset:5 Before unset:3 After unset:5 Before unset:4 After unset:5
Note: If a variable is declared static and if it is unset inside the function then, the affect will be in the rest of context of a function only. Above calls outside the function will restore the value.
- PHP | Program to delete an element from array using unset() function
- PHP | Unset() vs Unlink() Function
- PHP | Unset Session Variable
- Difference between revert and unset keyword in CSS
- CSS | unset keyword
- How to set and unset cookies using jQuery?
- CSS Value | Unset
- Lodash _.unset() Method
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.