16 of 410 menu

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

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

Example

Check if a variable exists:

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

Code execution result:

true

Example

Check multiple variables:

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

Code execution result:

false

Example

Check a non-existent variable:

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

Code execution result:

false

See Also

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