
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP NULL
Definition and Usage
In PHP, a variable with no value is said to be of null data type. Such a variable has a value defined as NULL. A variable can be explicitly assigned NULL or its value been set to null by using unset() function.
Syntax
$var=NULL;
It is possible to cast variable of other type to null, although casting null to other type has been deprecated from PHP 7.2. In earlier versions, casting was done using (unset)$var syntax
Following example shows how to assign NULL to a variable
Example
<?php $var=NULL; var_dump($var); ?>
Output
This will produce following result −
NULL
Following example performs null variable to other primary variables
Example
<?php $var = NULL; var_dump( (int) $var); var_dump((float)$var); var_dump((bool) $var) ; var_dump( (boolean) $var); ?>
Output
This will produce following result −
int(0) float(0) bool(false) bool(false)
- Related Articles
- How to remove null values with PHP?
- Difference between the Ternary operator and Null coalescing operator in php
- Is it possible to have a HTML SELECT/OPTION value as NULL using PHP?
- How can we handle NULL values stored in a MySQL table by using PHP script?
- Difference Between MySql NULL and IS NOT NULL?
- Working with NULL and IS NOT NULL in MySQL
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- Return null for date_format when input is null in MySQL?
- How does COALESCE order results with NULL and NON-NULL values?
- What is the benefit of MySQL ‘IS NULL’ and ‘IS NOT NULL’?
- Insert default into not null column if value is null in MySQL?
- Sum if all rows are not null else return null in MySQL?
- Fetch maximum value from multiple columns with null and non-null values?
- In MySQL what is the difference between != NULL and IS NOT NULL?
- CASE WHEN column1 IS NULL THEN NULL ELSE column2 END with MySQL

Advertisements