Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

isset

Checks that a variable exists and is not null.

Syntax

isset(mixed $var, mixed ...$vars): bool

Parameters

ParameterTypeDescription
$varmixedA variable, an array element or a property.
...$varsmixedOther variables; all of them must exist.

Return value

bool`true` if the value exists and is not `null`.

Examples

An existing and a missing variable:

<?php
 
$name = 'Anna';
 
var_dump(isset($name));
var_dump(isset($age));

Output:

bool(true)
bool(false)

An array element, and the short form with ??:

<?php
 
$user = ['name' => 'Anna'];
 
var_dump(isset($user['email']));
echo $user['email'] ?? 'not set';

Output:

bool(false)
not set

Notes

For 0, an empty string and false the function returns true — those values exist. It gives false only for null and missing variables.

See also

  • empty — Checks that a variable does not exist or holds an "empty" value.
  • array_key_exists — Checks whether an array has a key.
  • is_null — Checks whether a value is null.

Related recipes

In the tutorial

  • Variables — How to declare variables in PHP, name them and interpolate them into strings.

Thanks for reading!

Donate to the site — we work hard for you.