Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

is_null

Checks whether a value is null.

Syntax

is_null(mixed $value): bool

Parameters

ParameterTypeDescription
$valuemixedThe value to check.

Return value

bool`true` if the value is `null`.

Examples

Only null gives true:

<?php
 
var_dump(is_null(null));
var_dump(is_null(0));
var_dump(is_null(''));

Output:

bool(true)
bool(false)
bool(false)

The same with a strict comparison:

<?php
 
$result = null;
 
var_dump($result === null);

Output:

bool(true)

Notes

The comparison $value === null does the same and is more common.

See also

  • isset — Checks that a variable exists and is not null.
  • gettype — Returns the name of a value's type.

In the tutorial

  • Data types — The main PHP data types — strings, numbers, booleans, arrays and null.

Thanks for reading!

Donate to the site — we work hard for you.