Thursday, September 4, 2025
HomeLanguagesis_null($x) vs $x === null in PHP

is_null($x) vs $x === null in PHP

is_null() Function

This is_null() function is an inbuilt function in PHP which is used to find whether a variable is NULL or not. It returns True if the given variable is null, otherwise return False.

Syntax:

bool is_null( $var )

Example 1:




<?php
// PHP program to illustrate
// is_null() function
  
// Declare variable and initialize it
$x = NULL;
$y = 15;
  
// Use is_null() function and 
// display the result
var_dump(is_null($x));
  
var_dump(is_null($y));
  
?>


Output:

bool(true)
bool(false)

$x === null

It is an identical comparison operator and it returns true if the value of $x is equal to NULL. Null is a special data type in PHP which can have only one value that is NULL. A variable of data type NULL is a variable that has no value assigned to it. Any variable can be empty by setting the value NULL to the variable.

Syntax:

$var === null

Example:




<?php
// PHP program to demonstrate
// === operator
  
// Declare variable and initialize it
$x = "neveropen";
  
if ($x === null)
    echo "True \n";
else 
    echo "False \n";
  
// Declare variable and initialize it   
$y = NULL;
  
if ($y === null)
    echo "True";
else 
    echo "False";
      
?>


Output:

False 
True
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS