PHP isset() Function

PHP isset() function is “used to check if a variable is set and not NULL.”

Syntax

bool isset($var, mixed)

Parameters

  1. $var(required): This is the variable to be checked.
  2. mixed(optional):  It indicates that a parameter may accept multiple types.

Return value

It returns TRUE, and If the variable exists and is not NULL else, it returns FALSE.

Visual RepresentationVisual Representation of PHP isset() Function

Example 1: How to Use isset() Function

<?php

$stranger = 'Eleven';

var_dump(isset($stranger));

Output

bool(true) 

Example 2: Checking the empty stringVisual Representation of Checking the empty string

<?php

$stranger = '';

var_dump(isset($stranger));

Output

bool(true) 

In PHP, an empty string is different from NULL, and therefore, it is considered a valid value.

Example 3: Checking for the NULL valueVisual Representation of Checking for the NULL value

<?php

$stranger = NULL;

var_dump(isset($stranger));

Output

bool(false)

PHP Fatal error: Cannot use isset() on the result of an expression

<?php

var_dump(isset('Eleven'));

Output

PHP Fatal error: Cannot use isset() on the result of an expression 
(you can use "null !== expression" instead) in
     /Users/krunal/Desktop/code/php/pro/app.php on line 3

Fatal error: Cannot use isset() on the result of an expression 
(you can use "null !== expression" instead) in 
   /Users/krunal/Desktop/code/php/pro/app.php on line 3

That’s it.

1 thought on “PHP isset() Function”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.