Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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)
Advertisements
