isset Function in PHP
In this article, we will discuss the isset function in php with an example code. It checks the variable we have created or not. We put the condition in “if statement”. For example, see the below code:
<html> <body> <?php $myVar1 = "hello"; if (isset($myVar1)) echo "myVar1 is set <br/>"; else echo "myVar1 is not set <br/>"; if (isset($myVar2)) echo "myVar2 is set <br/>"; else echo "myVar2 is not set <br/>"; ?> </body> </html>
I want to check if the variable “myvar1” is present or not. If the variable is present, it returns “it is set” otherwise it returns “It is not set”.
Here, we have created the variable “myVar1”, so it returns “myVar1 is set”. We haven’t created the variable “myVar2”, so it returns “myVar2 is not set.