PHP isset() function

PHP isset is used to check whether the variable is set or not.The PHP isset() function returns false if variable contains a NULL value.

Syntax:

Presentation of PHP isset:

Presentation of PHP isset

  • In the above diagram, the isset variable is null so it will return false.

Isset Variable

  • In the above diagram, the isset variable is 10, and it will return true. It means if the variable is set and not null, then the isset() function will return true.

Example (Null Variable):

Output:

  • In the above example, the variable is null, and it will return the false result.

Example (Not NullVariable):

Output:

  • In the above example, the variable has 2 value, and it will return true

Example:

  • In the above example, the PHP isset() function is to check the variable ($gender) is set or not with a value( “female, male and trans”). 

isset vs. empty vs. is_null :

  • isset() is to check if a variable is set with a value.
  • empty() is to check if a given variable is empty.
  • is_null() – It is to check whether a variable is defined as NULL.

 

 

Functions “” Null False Undefined 0
isset() True False True False True
empty() True True True True True
is_null() False True False Error False