How to check Whether a Variable is Null in PHP? Last Updated : 21 Apr, 2025 Comments Improve Suggest changes Like Article Like Report We are given a variable and the task is to check whether the value of the given variable is null or not and returns a Boolean value using PHP. To check a variable is null or not, we use is_null() function. A variable is considered to be NULL if it does not store any value. It returns TRUE if the value of variable $var is NULL, otherwise, returns FALSE.Syntax:boolean is_null( $var )Example: This example checks whether a variable is null in PHP or not. PHP <?php // PHP Program to check whether // a variable is null or not? $var1 = NULL; $var2 = "\0"; // "\0" means null character $var3 = "NULL"; // $var1 has NULL value, so always give TRUE is_null($var1) ? print_r("True\n") : print_r("False\n"); // $var2 has '\0' value which consider as null in // c and c++ but here taken as string, gives FALSE is_null($var2) ? print_r("True\n") : print_r("False\n"); // $var3 has NULL string value so it will false is_null($var3) ? print_r("True\n") : print_r("False\n"); ?> Output:TrueFalseFalse Comment More infoAdvertise with us Next Article How to check Whether a Variable is Null in PHP? M manaschhabra2 Follow Improve Article Tags : Web Technologies PHP PHP Programs PHP-Misc Similar Reads How to check whether a variable is set or not using PHP ? We have given a variable and the task is to check whether a variable var is set or not in PHP. In order to do this task, we have the following methods in PHP: Approach 1: Using isset() Method: The isset() method returns True if the variable is declared and its value is not equal to NULL. Syntax: boo 2 min read How to check whether an array is empty using PHP? In PHP, arrays are commonly used data structures that can hold multiple values. However, sometimes it is necessary to check whether an array is empty, i.e., whether it has no elements. This is useful when the array is filled with data automatically, and you need to check if it has any data before pe 3 min read PHP | Check if a variable is a function To determine whether a passed argument is a function or not, Few of the most preferred methods are shown below. Using is_callable() Function: It is an inbuilt function in PHP which is used to verify the contents of a variable in called as a function. It can check that a simple variable contains the 3 min read How to read if a checkbox is checked in PHP? Using isset() Function The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases. This 2 min read How to Check a Value Exist at Certain Index in an Array in PHP? Given an array and index, the task is to check whether a value exists or not at a certain index in an array in PHP. Below are the approaches to check if a value exists at a certain index or not in an array in PHP:Table of ContentUsing isset() FunctionUsing array_key_exists() FunctionUsing key_exists 3 min read PHP Program to Check the Given Matrix is Sparse or Not A matrix is a two-dimensional data object having m rows and n columns, therefore a total of m*n values. If most of the values of a matrix are 0 then we say that the matrix is sparse. Consider a definition of Sparse where a matrix is considered sparse if the number of 0s is more than half of the elem 2 min read How to check the existence of URL in PHP? Existence of an URL can be checked by checking the status code in the response header. The status code 200 is Standard response for successful HTTP requests and status code 404 means URL doesn't exist. Used Functions: get_headers() Function: It fetches all the headers sent by the server in response 2 min read How to create optional arguments in PHP ? Arguments that do not stop the function from working even though there is nothing passed to it are known as optional arguments. Arguments whose presence is completely optional, their value will be taken by the program if provided. But if no value is given for a certain argument, the program will not 2 min read How to avoid undefined offset error in PHP ? The Offset that does not exist in an array then it is called as an undefined offset. Undefined offset error is similar to ArrayOutOfBoundException in Java. If we access an index that does not exist or an empty offset, it will lead to an undefined offset error.Example: Following PHP code explains how 2 min read Ternary operator vs Null coalescing operator in PHP Ternary Operator Ternary operator is the conditional operator which helps to cut the number of lines in the coding while performing comparisons and conditionals. It is an alternative method of using if else and nested if else statements. The order of execution is from left to right. It is absolutely 3 min read Like