PHP unset() Function

PHP unset() Function is used to unset a variable. PHP unset() function is PHP built-in function.

It unsets the local variables. If You want to unset the global variable inside the function, then you have to use $GLOBALS array to do so.

What is use of PHP unset() function?

PHP unset() Function is used to destory given variable.

Syntax for unset:

unset(mixed $var, ....);

Parameter,

$var :  Required. It specifies the variable to reset.
.... : Optional. Pass Multiple variables.

Return Values for unset :

The unset() function doesn't return any value.

Note : When you are using unset() function on inaccessible object properties, the __unset() overloading method will be called, if It is declared.

Let's see below example to understand php unset() Function in details.

Example :

<?php
$var = "Learn PHP unset() Function tutorial.";
echo "<br>The value of variable 'var' before unset : " . $var ;
unset($var);
echo "<br>The value of variable 'var' after unset : " . $var;
?>

Output :

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

82556