In this article you are going to learn the use of isset() and unset() function in php programming language. Both of them are variable handling functions and have similar syntax. However, they differ in their functionalities.
While isset() function specifies whether a variable is declared or set in the php script and doesn’t have a null value, an unset() function clears or unset the defined variable in the php script.
In simple words, isset() function is used to examine whether the value of a variable exists or not and unset() function is used to destroy a defined variable. If you are php lover and looking to upgrade your skills in php, you may also join our php training in gurugram to boost up your advanced php skills.
Now let’s briefly describe these two variable handling functions one by one to make this concept more clear to you.
ISSET() FUNCTION
Syntax : isset($variable1, $variable2, $variable3, $…..);
As described earlier, this predefined boolean function is used to examine whether the value of a variable is set or not. It can be used to examine more than one variable as well.
Similar type of parameters(variables) can be used multiple times as shown in the syntax above.
$variable1- it represents the first variable to be examined.
$variable2- second variable to be examined.
$variable3- third variable to be examined.
$…..- other variables to be examined, if any.
The above parameters may have mixed values(string, array, integer, floats etc.) of the arguments.
Result/Return Value : This function will return Boolean value ‘True’ if the variable exists and ‘False’ if the variable doesn’t exists or has a value equal to Null. If multiple variables have been used, they must be set or have existence in order to return True. If they all are not set, it will return False.
Errors : Isset() function is used to pass only the variables. If parameters other than variables are passed, it will show a Parse Error.

Example : An example of isset() function is shown below.

Output : You will get a signup page by using the above php script in the output in which the user is required to enter the information.

If the user is registered, then, after entering the information in the signup page and submitting it, user will get a message ‘already registered’ as shown in the image below.
UNSET() FUNCTION
Syntax : unset($variable1, $variable2, $variable3, $…..);
This predefined function is used to clear or unset a specified variable in the php script. It can be used to unset more than one variable as well.
Following are the parameters used in the unset() function.
$variable1- it represents the first variable to be cleared.
$variable2- second variable to be cleared.
$variable3- third variable to be cleared.
$…..- other variables to be cleared, if any.
Result/Return Value : It returns no value, i.e. void
Errors : Like isset() function, this is also used to pass only the variables, passing others will result in a Parse Error.

Example : An example of unset() function is shown below.

Output : You will get the following output using the above php script.
We have tried to provide you the best possible information about the use of isset() and unset() functions in php programming language. Hope you liked this post. For further updates, stay tuned to our php blogs.