PHP中的'isset()'和'!empty()'有什么区别?
Isset功能
ISSET检查变量以查看是否已设置。换句话说,它检查变量是否为除NULL以外的任何值或未分配值。如果变量存在并且具有非NULL的值,则ISSET返回TRUE。这意味着设置了分配了“”,“0”,“0”或“FALSE”的变量,因此对于ISSET为TRUE。
示例
<?php
$val = '0';
if( isset($val)) {
print_r(" $val is set with isset function <br>");
}
$my_array = array();
echo isset($my_array['New_value']) ?
'array is set.' : 'array is not set.';
?>输出结果
这将产生以下输出-
0 is set with isset function array is not set.
空功能
EMPTY检查变量是否为空。空解释为:“”(空字符串),0(整数),0.0(浮点数),“0”(字符串),NULL,FALSE,array()(空数组)和“$var;”(已声明的变量,但在类中没有值。
示例
<?php
$temp_val = 0;
if (empty($temp_val)) {
echo $temp_val . ' is considered empty';
}
echo "nn";
$new_val = 1;
if (!empty($new_val)) {
echo $new_val . ' is considered set';
}
?>输出结果
这将产生以下输出-
0 is considered empty 1 is considered set
热门推荐
10 学生节祝福语简短大全
11 入学祝福语简短走心
12 祝球员赛前祝福语简短
13 牛年除夕祝福语简短的
14 祖国七十华诞简短祝福语
15 双节祝福语简短唯美
16 晚儿子生日祝福语简短
17 祝福语怎么写大全简短
18 订婚新发言简短祝福语