Isset and Unset in PHP

PHP isset() and unset() Function; Through this tutorial, i am going to show you PHP isset() and unset() function and uses of isset and unset function in PHP.

PHP Isset and unset Function

Let’s see the isset and unset function of PHP with its syntax and examples:

  • PHP isset() Function :- The isset function in PHP is used to determine whether a variable is set or not
  • PHP unset() Function :-The unset() function in PHP resets any variable.

PHP isset() Function

In php, Isset() function is used to check whether a variable is set or not.

Syntax – PHP isset() function

The basic Syntax of PHP isset() function is:

isset($variable);

Note:- If use isset() function in PHP, PHP isset() function returns true if a variable is set and if it is not set it will be false.

Example 1 – PHP isset Function

Let’s take example using php isset() function; is as follows:

<?php
	$issetVal = "";
	If (isset($issetVal)){
	   echo "The variable is set";
	}
	else {
	    echo "The variable is not set";   
	}
?>

Example 2 – PHP isset() function

Let’s take an second example using php isset() function; is as follows:

<?php
	$issetVal;
	if(isset($issetVal)){
	   echo "Result:- The variable is set";
	}
	else {
	    echo "Result:- The variable is not set";   
	}
?>

PHP unset() Function

In PHP, unset() function is used to destroy a defined variable.

Syntax – PHP unset() function

The basic Syntax of PHP unset() function is:

unset($variable_name);

Note: When you use the PHP unset function, You may specify one or more variable to be destroyed by using the unset in a single call.

Example 1 – PHP unset Function

Let’s take an example using unset() function in PHP; is as follows:

<?php
	$str = "This is simple string";
	//Using unset function
	unset ($str);
	//
	If (isset($str)){
	   echo "The variable is set";
	}
	else {
	    echo "The variable is not set";   
	}
?>

Recommended PHP Tutorials

Leave a Comment