Home >Backend Development >PHP Tutorial >php empty() function in detail_PHP tutorial

php empty() function in detail_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:55:251419browse

Today we are going to talk about the usage of the empty function, what is the difference between it and waiting for empty, and whether it returns a normal value when using it to operate an array. Friends in need can refer to it.

 代码如下 复制代码
$array1=array();
print_r($array1);
if(empty($array1)){
echo '对empty()来说是空数组(an empty array)';
}
else{
echo '对empty()来说是非空数组(an noempty array)';
}
?>
显示结果:######################
Array
(
)
对empty()来说是an empty array

###############################

 代码如下 复制代码
$array1=array();
$array1[]='';
print_r($array1);
if(empty($array1)){
echo '对empty()来说是空数组(an empty array)';
}
else{
echo '对empty()来说是非空数组(an noempty array)';
}
?>
显示结果:######################
Array
(
    [0] =>
)
对empty()来说是非空数组(an noempty array)
###############################

This is not an empty array because one of its elements is an empty character (""). Please pay attention to the difference from an empty character ("" (an empty string));

actually
empty($x) is equal to !isset($x) || !$x
!empty($x) is equal to isset($x) && $x

About empty function syntax

empty -- Check if a variable is empty
Description
bool empty (mixed var)


If var is a non-empty or non-zero value, empty() returns FALSE. In other words, "", 0, "0", NULL, FALSE, array(), var $var; and objects without any properties will be considered empty, and TRUE is returned if var is empty.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632256.htmlTechArticleToday we are going to talk about the usage of the empty function, what is the difference between it and wait for empty, and how to use it to operate arrays Does it return a normal value? Friends in need can refer to it. Code...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn