How to use PHP isset to check if a variable value is set?

What is the isset function?

PHP provides a function isset() to see if a variable is set or not. It means PHP isset() function checks if a variable is already assigned a value or not?

See an example of isset function

How to use the isset function?

Following is the general syntax of using the isset function:

isset($variable_name);

You can check one or more variables at one call.

Example of using isset function in PHP

A very simple program to test isset PHP function is as follows:

PHP isset function

Experience this example online



Output

var1 is set

var2 is not set

In the above example, you can see the var1 is assigned a value before using the isset with the if statement. As it was set, i.e. assigned a value, the if statement returned true.

On the other hand, the var2 is not assigned any value and in the if statement it executed the else part that means the condition was false.

Please note if a variable is unset by using the unset() function it can no longer be set.


Was this article helpful?

Related Articles

Leave A Comment?