EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

PHP is_null()

Home » Software Development » Software Development Tutorials » PHP Tutorial » PHP is_null()

PHP is_null()

Introduction to PHP is_null()

The PHP is_null() function is actually an in-built function of the PHP Programming Language which help us to find whether the variable is a NULL value or not. The PHP is_null() function works for PHP 4 and the above PHP versions which are introduced later after PHP 4 version. The type of the $variable_name parameter of the is_null() function is Boolean type value. Is_null() function of PHP accepts only one parameter and that too it is fully mandatory parameter. There are no optional parameters available inside of the is_null() PHP function.

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

is_null( $variable_name )

Explanation of Parameter:

The is_null() function of PHP Programming Language usually accepts only one single parameter as mentioned in the above syntax.

  • $variable_name:The $variable name helps us to check whether the variable’s value is NULL or not. It is a mandatory parameter. There are no more optional parameters available inside of the is_null() function to mention.

Return value:

The is_null() function will return a Boolean value and the function is going to return TRUE only when the $variable_name is the NULL value, if the variable’s value is not NULL then it will return FALSE statement.

Working of is_null() Function in PHP

  • PHP is_null() function woks based on the NULL values present inside of the function’s parenthesis.
  • If the variable value inside of the is_null() function then the result will be TRUE and promotes the further conditions statement or any other.
  • If the variable’s value inside of the is_null() function is FALSE then statements which are inside of the those conditions will not be executed.
  • The value type of the PHP is_null() function is Boolean.
  • The only parameter of the is_null() function is a mixed type (mixed type means that it is going to indicate that the parameter has the capability of accepting the multiple types but not necessarily all types).

Examples of PHP is_null()

Given below are the examples mentioned:

Example #1

In the below example, four variables is created with different variables and checked whether they are NULL values or not with the help of is_null() function of the PHP programming language. At first, $var11, $var12, $var13 and $var14 variables are created with different values for them. $var11 and $var13 variables are stored with “NULL” values. $var12 and $var14 values are stored with “\0” and 0 values. \0 is considered as NULL but here it is assigned as a string value. Then “is_null() ? TRUE : FALSE” structured syntax is used to print the TRUE statements/others only if the is_null($variable_name) is TRUE. If not FALSE statement will be printed. Likewise the code implements the results below. Checking the $var11 and $var13 variable’s values using the is_null() function will print the TRUE value whereas for other variables ($var12 and $var14) the result will be FALSE value.

Syntax:

<?php
$var11 = NULL;
$var12 = "\0";
$var13 = "NULL";
$var14 = 0;
is_null($var11) ?print_r("Null Value So True\n") : print_r("False\n");
is_null($var12) ?print_r("Null Value So True\n") : print_r("Not Null so False\n");
is_null($var13) ?print_r("Null Value So True\n") : print_r("Not Null so False\n");
is_null($var14) ?print_r("Null Value So True\n") : print_r("Not Null so False\n");
?>

Output:

php is_null() 1

Example #2

This is the example of demonstrating the working of the is_null() function of the PHP Programming Language. At first, a function “check_null1()” is created with only one parameter “$var11” in it. Inside of the function is_null() function is created to check whether the variable parameter of the function is TRUE or NOT. But here variable value of $var11 is not mentioned. Function is closed and called many times with different inputs. “NULL” is mentioned/passed to the $var11 by changing the capitalization of the NULL words as values. But for the last 3 echo statements, different values passed to the variable parameter of the function. So for the last echo statements the result will be FALSE.

Syntax:

<?php
function check_null1($var11)
{
return (is_null($var11) ? "Null Value so :: True" : "Not Null Value so :: False");
}
echo check_null1(NULL) . "\n";
echo check_null1(null) . "\n";
echo check_null1(Null) . "\n";
echo check_null1(NUll) . "\n";
echo check_null1(NULl) . "\n";
echo check_null1(nulL) . "\n";
echo check_null1(nuLL) . "\n";
echo check_null1(nULL) . "\n";
echo check_null1('Nul') . "\n";
echo check_null1(false) . "\n";
echo check_null1(2). "\n";
?>

Output:

check whether the variable parameter of the function is TRUE or NOT

Example #3

In the below example, $a1, $b1, $c1 and $d1 variables are created. NULL values are passed to $b1 and $d1 variables. Although “null” value is passed to the $c1 variable, but the NULL is passed as a string value. So the result of the $b1 and $d1 variable’s after checking with the is_null() function will be printed as empty value. For $a1 and $c1 variables, result will not all be print.

Popular Course in this category
PHP Training (5 Courses, 3 Project)5 Online Courses | 3 Hands-on Project | 28+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,726 ratings)
Course Price

View Course

Related Courses
Java Servlet Training (6 Courses, 12 Projects)All in One Software Development Bundle (600+ Courses, 50+ projects)

Syntax:

<?php
echo "For Non-NULL values the value will not be printed . Check Below :: \n";
$a1 = 0;
echo "a1 is :: " . is_null($a1) . "\n";
$b1 = null;
echo "b1 is :: " . is_null($b1) . "\n";
$c1 = "null";
echo "c1 is :: " . is_null($c1) . "\n";
$d1 = NULL;
echo "d1 is :: " . is_null($d1) . "\n";
?>

Output:

php is_null() 3

Example #4

This is the example of checking for different $var11 variable’s values whether they are NULL or not. This is done by using different IF and ELSE conditions. At first, $var11 is stored with “TRUE” value and checked with the is_null() function so the ELSE condition result will be printed because the is_null(TRUE) function condition result is FALSE. Likewise for the second IF and ELSE condition, same result is printed. Then for the $var11 variable, “NULL” value is passed and then after checking with the is_null() function the result will show that “Variable var11 is NULL” like that.

Syntax:

<?php
echo "Checking for TRUE value of the var11 variable for NULL :: \n";
$var11 = TRUE;
if (is_null($var11))
{
echo 'Variable var11 is  NULL';
}
else
{
echo 'Variable var11 is not NULL';
}
echo "\n";
echo "Checking for FALSE value of the var11 variable for NULL :: \n";
$var11 = FALSE;
if (is_null($var11))
{
echo 'Variable var11 is  NULL';
}
else
{
echo 'Variable var11 is not NULL';
}
echo "\n";
echo "Checking for NULL value of the var11 variable for NULL :: \n";
$var11 = NULL;
if (is_null($var11))
{
echo 'Variable var11 is  NULL';
}
else
{
echo 'Variable var11 is not NULL';
}
echo "\n";
?>

Output:

done by if and else condition

Conclusion

Here we saw introduction of PHP is_null() function with the syntax and it’s parameters explanation, working of PHP is_null() function along with various examples which involves is_null() function to understand the is_null() function well.

Recommended Articles

This is a guide to PHP is_null(). Here we discuss the introduction to PHP is_null() with respective examples for better understanding. You may also have a look at the following articles to learn more –

  1. PHP Log Errors
  2. PHP preg_split()
  3. PHP References
  4. PHP Data Object

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PHP Tutorial
  • Functions
    • Functions in PHP
    • PHP Math Functions
    • PHP Recursive Function
    • PHP String Functions
    • Hashing Function in PHP
    • Date Function in PHP
    • PHP Anonymous Function
    • Calendar in PHP
    • PHP Call Function
    • PHP Pass by Reference
    • PHP ucfirst()
    • PHP ucwords()
    • trim() in PHP
    • isset() Function in PHP
    • PHP replace
    • PHP fpm
    • PHP strpos
    • preg_match in PHP
    • PHP preg_replace()
    • PHP ob_start()
    • PHP Reflection
    • PHP Split String
    • PHP URL
    • PHP preg_match_all
    • PHP strtoupper()
    • PHP preg_split()
    • PHP substr_replace()
    • PHP setlocale()
    • PHP substr_count()
    • PHP Serialize
    • PHP strlen()
    • PHP async
    • PHP Date Time Functions
    • PHP timezone
    • PHP Data Object
    • print_r() in PHP
    • PHP header()
    • PHP strip_tags()
    • PHP chop()
    • PHP MD5()
    • PHP unset()
    • PHP crypt()
    • PHP wordwrap()
    • PHP is_null()
    • PHP strtok()
    • PHP bin2hex()
    • PHP parse_str()
    • PHP levenshtein()
    • PHP addslashes()
    • PHP strtotime
    • PHP sha1()
    • PHP explode()
    • PHP sscanf()
    • PHP require_once
    • PHP Zip Files
    • PHP $_SERVER
    • PHP $_POST
    • PHP Include and Require
    • PHP POST Method
  • PHP Basic
    • Introduction To PHP
    • What is PHP
    • PHP Keywords
    • Advantages of PHP
    • Career In PHP
    • Comments in PHP
    • PHP Commands
    • PHP Frameworks
    • PHP Compiler
    • Variables in PHP
    • PHP Superglobal Variables
    • PHP Versions
    • Object in PHP
    • What is Drupal
    • Top PHP Frameworks
    • WebStorm IDE
    • What is phpMyAdmin?
    • PhpStorm
    • Install phpMyAdmin
    • Phalcon Model
  • Data Types
    • PHP Data Types
    • PHP Integer
    • PHP Booleans
  • Operators
    • PHP Operators
    • Arithmetic Operators in PHP
    • Comparison Operators in PHP
    • Logical Operators in PHP
    • Bitwise Operators in PHP
    • Ternary Operator in PHP
    • PHP String Operators
  • Control Statements
    • Control Statement in PHP
    • PHP if Statement
    • if else Statement in PHP
    • elseif in PHP
    • PHP Switch Statement
    • Continue in PHP
    • Break in PHP
  • Loops
    • PHP Loops
    • For Loop in PHP
    • PHP Do While Loop
    • PHP While Loop
    • While Loop in PHP
    • Foreach Loop in PHP
  • Constructor
    • Constructor in PHP
    • Destructor in PHP
  • State Management
    • Cookie in PHP
    • Sessions in PHP
  • Array
    • What is PHP Array
    • Arrays in PHP
    • 2D Arrays in PHP
    • Associative Array in PHP 
    • Multidimensional Array in PHP
    • Indexed Array in PHP
    • PHP Array Functions
    • PHP unset Array
    • PHP Append Array
    • PHP Array Search
    • PHP Split Array
    • PHP array_push()
    • PHP array_pop()
  • Advanced
    • Overloading in PHP
    • Overriding in PHP
    • Method Overloading in PHP
    • Inheritance in PHP
    • Multiple Inheritance in PHP
    • PHP Interface
    • Encapsulation in PHP
    • PHP Constants
    • PHP Magic Constants
    • PHP Regular Expressions
    • PHP GET Method
    • PHP Annotations
    • PHP Encryption
    • PHP file Functions
    • PHP readfile
    • PHP?Write File
    • PHP Append File
    • PHP Type Hinting
    • PHP Filters
    • PHP Float
    • PHP Form
    • PHP Form Validation
    • Sorting in PHP
    • PHP usort()
    • PHP Stack Trace
    • PHP Stack Overflow
    • PHP Pagination
    • PHP implode
    • Polymorphism in PHP
    • Abstract Class in PHP
    • PHP Final Class
    • PHP Custom Exception
    • error_reporting() in PHP
    • PHP Log Errors
    • Access Modifiers in PHP
    • PHP Change Date Format
    • Static Method in PHP
    • PHP File Handling
    • PHP Output Buffering
    • Get IP Address in PHP
    • Upload a File in PHP
    • String in PHP
    • Public Function in PHP
    • Private in PHP
    • Protected in PHP
    • basename in PHP
    • Validation in PHP
    • PHP mail()
    • PHP Email Form
    • PHP Directory
    • PHP Create Session
    • PHP include_once
    • PHP json_decode
    • PHP XMLWriter
    • PHP XML Reader
    • PHP XML Parser
    • PHP XML into Array
    • Phalcon Framework
  • Programs
    • Patterns in PHP
    • Star Patterns in PHP
    • Swapping in PHP
    • Fibonacci Series PHP
    • Factorial in PHP
    • Reverse String in PHP
    • Square Root in PHP
    • Random Number Generator in PHP
    • Palindrome in PHP
    • Prime Numbers in PHP
    • Armstrong Number in PHP
    • Socket Programming in PHP
    • Login Page in PHP
    • PHP Login Template
    • PHP Object to String
  • Database
    • PHP Database Connection
    • How to Connect Database to PHP
  • Interview Questions
    • PHP Interview Questions
    • PHP OOP Interview Questions
    • CakePHP Interview Questions
    • Core PHP Interview Questions

Related Courses

PHP Training Course

Java Servlet Training

Software Development Course Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - PHP Training Course Learn More