PHP中empty,is_null,isset,array() 中的异同和功能
来源:互联网 发布:手机笑声软件 编辑:程序博客网 时间:2024/05/22 11:57
PHP中empty,is_null,isset,array() 中的异同和功能
empty
bool empty ( mixed var )
- <?php
- $var
= 0; - //
结果为 true,因为 $var 为空 - if
( empty($var)){ -
echo '$var is ;either 0 or not set at all' - }
- //
结果为 false,因为 $var 已设置 - if
(!isset( $var)){ -
echo '$var is ;not set at all' - }
- ?>
empty()只检测变量,检测任何非变量的东西都将导致解析错误。换句话说,后边的语句将不会起作用: empty(addslashes($name)) 。
isset
如果已经使用 unset() 释放了一个变量之后,它将不再是isset() 。若使用 isset() 测试一个被设置成 NULL 的变量,将返回FALSE 。同时要注意的是一个 NULL 字节("\0" )并不等同于 PHP 的NULL 常数。
isset() 只能用于变量,因为传递任何其它参数都将造成解析错误。若想检测常量是否已设置,可使用defined() 函数。
- <?php
- $var
= ''; -
// 结果为 TRUE,所以后边的文本将被打印出来。 - if
(isset( $var)){ -
print "This var ;is set set so I will print." - }
- //
在后边的例子中,我们将使用 var_dump 输出 isset() 的返回值。 - $a
= "test"; - $b
= "anothertest"; -
- var_dump(
isset($a) ); //TRUE - var_dump(
isset ($a, $b) ); //TRUE -
- unset
($a); -
- var_dump(
isset ($a) ); //FALSE - var_dump(
isset ($a, $b) ); //FALSE -
- $foo
= NULL; - var_dump(
isset ($foo) ); //FALSE -
- ?>
- <?php
-
- $a
= array( 'test'=> 'hello'1, => NULL); -
- var_dump(
isset ($a['test']) ); //TRUE - var_dump(
isset ($a['foo']) ); //FALSE - var_dump(
isset ($a['hello']) ); //FALSE -
- //
键 'hello' 的值等于 NULL,所以被认为是未置值的。 - //
如果想检测 NULL 键值,可以试试下边的方法。 - var_dump(
array_key_exists('hello', $a) ); //TRUE -
- ?>
is_null
如果 var 是 null 则返回 TRUE ,否则返回FALSE 。
总结:
empty在变量为null,0,"",'0',array()返回true
isset在判断null时返回false
is_null只要是null返回true,否则返回false
理解了这些,这三个函数足以区别开来了.
- PHP中empty,is_null,isset,array() 中的异同和功能
- PHP中isset,empty,is_null的使用方法和区别
- 综合归纳:PHP中empty()、is_null()和isset()的区别
- PHP isset(),empty(),is_null()
- php empty isset is_null
- php empty() isset() is_null()
- isset 和empty 区别: php中is_null,empty,isset,unset 的区别详细介绍
- php中empty() isset() is_null()函数比较
- php中empty() isset() is_null() 的区别
- php中empty(), is_null(), isset()函数区别
- PHP中isset、empty、is_null实验测试
- php中empty(), is_null(), isset()函数区别
- PHP中 is_null、empty、isset的区别
- php中is_null,isset,empty的总结
- php empty,isset,is_null比较(差异与异同)
- php empty,isset,is_null比较(差异与异同)
- php empty,isset,is_null比较(差异与异同)
- php empty,isset,is_null比较
- Android 自动更新APK
- PHP echo输出的内容包含html ,但是html不解析的不完全解决办法
- oracle中exp,imp的使用详解
- 响应式Web设计(三):响应式Web设计的方法
- auto_ptr、shared_ptr、unique_ptr 几句代码你就懂了
- PHP中empty,is_null,isset,array() 中的异同和功能
- 将一个数转换为字符输出
- HDU 4185 Oil Skimming ( 二分匹配建图 )
- Java 判断文件的字符集编码
- SQL优化总结
- 你的大四,推荐做的几件事 [英语专业女生的自白]
- 卡特兰数|斯特灵数
- hdu 2159 fate
- 高级Bash脚本编程指南(9):数字常量