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 生日广州男生祝福语简短