PHP unset() | Unset a Variable

The PHP unset() function is used, when we need to unset a variable. For example:

   $x = "";
   echo "The value of \$x is $x";
   echo "The value of \$x is $x";

The output produced by above PHP example on unset() function is:

php unset function

That is:

php unset example

PHP unset() Syntax

The syntax of unset() function in PHP, is:

unset(variableOne, variableTwo, variableThree, ..., variableN);

At least one variable is required. All the given variables as parameters, will get unset.

PHP unset a Session Variable

The PHP unset() function is used most of the time to unset a session variable. So to unset a session variable, follow this way:


Now the variable login is unset/deleted from the session.

PHP Online Test

« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook

Subscribe Us on YouTube