empty() determines whether an array or a variable is empty or not. is_null() is used for checking whether a variable is null or not .is_null() will return Boolean values(TRUE or FALSE).
But If we use empty() for checking a variable having value 0 ,it will return empty. But for is_null() will return FALSE.
<?php
$a=null;
if(is_null($a)) echo "value is not there";
else echo "value is there";
?>
Output : value is not there
<?php
$a=0;
if(is_null($a)) echo "value is not there";
else echo "value is there";
?>
Output : value is there
<?php
$a=0;
if(empty($a)) echo "value is not there";
else echo "value is there";
?>
Output : value is not there
But If we use empty() for checking a variable having value 0 ,it will return empty. But for is_null() will return FALSE.
<?php
$a=null;
if(is_null($a)) echo "value is not there";
else echo "value is there";
?>
Output : value is not there
<?php
$a=0;
if(is_null($a)) echo "value is not there";
else echo "value is there";
?>
Output : value is there
<?php
$a=0;
if(empty($a)) echo "value is not there";
else echo "value is there";
?>
Output : value is not there
0 comments:
Post a Comment