The isset Construct

The isset construct checks whether a variable exists and whether its value is not null. Returns true if the variable exists and is not equal to null, otherwise returns false. Can accept multiple parameters - in this case, it will return true only if all passed variables exist.

Syntax

phpisset($var);
phpisset($var1, $var2, ...);

Example

Check if a variable exists:

php<?php
  $var = 'test';
  var_dump(isset($var));
?>

Code execution result:

phptrue

Example

Check multiple variables:

php<?php
  $a = 1;
  $b = null;
  var_dump(isset($a, $b));
?>

Code execution result:

phpfalse

Example

Check a non-existent variable:

php<?php
  var_dump(isset($undefinedVar));
?>

Code execution result:

phpfalse

See Also

  • the empty function,
    which checks if a variable is empty
  • the is_null function,
    which checks a variable for null