How to check if a variable is empty in PHP?
The empty()
function is an in-built function in PHP which is used to check whether a variable is empty or not.
Example of empty function:
<?php
$var1 = "";
if(empty($var1))
{
echo"Yes, variable is empty";
}
else
{
echo"No, variable is not empty";
}
?>
Here is the list of values, that are returned as an empty
- “” (an empty string)
- 0(as an integer)
- 0.0(o as a float)
- “0”(o as a string)
- Null
- False
- array() (an empty array)
Learn more about the similar topics:
Tutorials |
---|
PHP Variables |
Interview Questions & Answers |
---|
How to check if a variable is empty in PHP? |
Is PHP a case sensitive language? |
What are the different data types in PHP? |