SQL PHP HTML ASP JavaScript articles and free scripts to download

empty()

Before using variable we can check by using empty function in PHP. The advantage of using empty function is it will not generate any error message if the variable does not exist. This function empty() will return True or False ( Boolean return ) based on status of the variable.
if(empty($my_var)){echo " Variable is empty ";}
else {echo " Variable is not empty ";}
The output of above command is here
Variable is empty
Note that there is no warning message. We will get True as return value from empty() if it is null data or 0 etc.

Here is a list for which we will get True as return value from empty function after checking.
For empty string like ""
Zero value string like "0"
Zero value of any integer
0.0 as float
Null
False
Empty array 
A variable declared but not assigned any value
We will add one more line to our above code and assign data to our variable $my_var
$my_var=0;
if(empty($my_var)){echo " Variable is empty ";}
else {echo " Variable is not empty ";}
Still we will get output as
Variable is empty

Google+
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer