PHP isset() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Variables

Definition

In PHP, isset() checks whether one or more variables are set and are not null. It looks like a function, but it is a language construct built into PHP itself.

isset() is the standard way to ask 'does this variable or array key exist?'. It never shows a warning for a missing variable or key, which makes it perfect for form data and configuration arrays. If you pass several variables, it only returns true when all of them are set.

Syntax

Call isset() with the values you need. Start with this line.

PHP
$ok = isset($user['name']);
CallWhat it does
isset($name)Returns true when $name exists and is not null.
isset($user['city'])Returns false if the key city does not exist or holds null.
isset($a, $b)Returns true only when both $a and $b are set and not null.

Because isset() is a language construct, you cannot call it through a variable function such as call_user_func('isset', $x). The ?? operator is a shorter way to write isset($x) ? $x : 'default'.

Library declarations
PHP
isset(mixed $var, mixed ...$vars): bool

Parameters

ParameterDescription
varRequired. The variable, array element or property to check. It must be written as a variable, not as a plain value.
varsOptional. Any number of extra variables to check. isset() returns true only if every one of them is set.

Return Value

Return ValueDescription
boolReturns true if all given variables exist and are not null, and false otherwise.

PHP Examples

Example 1 — Set, Null and Missing Variables

Check a variable with a value, one set to null, and one that was never created.

PHP
<?php
$name = 'Asha';
$empty = null;

var_dump(isset($name));
var_dump(isset($empty));
var_dump(isset($missing));

How It Works

  1. $name holds text. It exists and is not null, so isset() returns true.
  2. $empty holds null. isset() treats null as not set, so the result is false.
  3. $missing was never created. isset() returns false and does not show a warning.
  4. No warning appears for the missing variable. This is the main reason isset() is so popular.

Example 2 — Array Keys and Several Variables

Use isset() on array keys, and pass more than one value in a single call.

PHP
<?php
$user = ['name' => 'Asha', 'age' => 25, 'city' => null];

var_dump(isset($user['name']));
var_dump(isset($user['city']));
var_dump(isset($user['zip']));
var_dump(isset($user['name'], $user['age']));
var_dump(isset($user['name'], $user['city']));

How It Works

  1. The name key exists with a value. The first check returns true.
  2. The city key exists but holds null. isset() returns false for it.
  3. The zip key does not exist. The result is false and there is no warning.
  4. With two arguments, both must be set. name and age pass, but name with city fails because city is null.

Example 3 — Default Values

Use isset() and the ?? operator to fall back to a default when a setting is missing.

PHP
<?php
$settings = ['theme' => 'dark'];

$theme = isset($settings['theme']) ? $settings['theme'] : 'light';
$lang = $settings['lang'] ?? 'en';

echo $theme, PHP_EOL;
echo $lang, PHP_EOL;
echo isset($settings['theme']) && $settings['theme'] === 'dark' ? 'Dark mode' : 'Light mode', PHP_EOL;

How It Works

  1. The settings array has one key. Only theme is defined.
  2. The ternary uses isset(). Because theme is set, $theme gets the value dark.
  3. The ?? operator is a shortcut. It works like isset() and falls back to en because lang is missing.
  4. The last line combines isset() with a comparison. Both conditions are true, so it prints Dark mode.

Frequently Asked Questions

It checks whether a variable, array key or property exists and is not null. It returns true only if the value is set, and it never shows a warning for something that does not exist.
No. It is a language construct, like echo and unset(). This means it is handled directly by PHP, and you cannot use it as a callback name in functions like call_user_func().
isset() is false only for missing or null values. empty() is also true for 0, '0', an empty string, false and an empty array, so empty() catches more cases.
Yes. If a variable holds an empty string, isset($var) returns true because the value is not null. Use empty() or a strlen() check if you want to catch empty text.
They use the same rule, but ?? returns the value or a default in one step. $x ?? 'default' is the short form of isset($x) ? $x : 'default'.

Next: print_r()

print_r() prints a human-readable version of a value. It is mostly used to look inside arr.

print_r() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful