empty()

The following things are considered to be empty:

  • "" (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • var $var; (a variable declared, but without a value in a class)

对"空数组"的理解:array() (an empty array),数组元素个数为0.

<?php
$array1=array();
print_r($array1);
if(empty($array1)){
 echo '对empty()来说是空数组(an empty array)';
}
else{
    echo '对empty()来说是非空数组(an noempty array)';
}
?>
显示结果:######################
Array
(
)
对empty()来说是an empty array
###############################
<?php
$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)
###############################
  这个并不是空数组,因为它有一个元素为空字符(""),要注意和空字符("" (an empty string))区别;

 

posted @ 2011-11-09 17:48  飞天神鼠  阅读(355)  评论(0编辑  收藏  举报