Home  >  Article  >  Backend Development  >  PHP:empty,isset,is_null,array(零),array(),array(""),0,"0""""null"NULL的总结

PHP:empty,isset,is_null,array(零),array(),array(""),0,"0""""null"NULL的总结

WBOY
WBOYOriginal
2016-06-13 12:23:30809browse

PHP:empty,isset,is_null,array(0),array(),array(""),0,"0","","null",NULL的总结

通过下面这个程序来检测

$a=0;if(empty($a)){	echo "yes|";}else{	echo "no|";}if(isset($a)){	echo "yes|";}else{	echo "no|";}if(is_null($a)){	echo "yes|";}else{	echo "no|";}if($a){	echo "yes|";}else {	echo "no|";}

那么$a 分别取不同值的时候结果如下



总结:

empty的情况

1变量的值为空 $var = “”;

2变量的值为字符串0或者数字0  $var = 0 ; 或者$var =”0″

3变量的值为flase $var= flase;

4凡是为NULL的 都为空

5空数组  $arr =array();

6变量只定义不赋值$var;

isset的情况

查看一个变量是否已经被设置并且不为空(Determine if a variable is set and is not NULL)

is_null

判断null

判断是否为假

1变量的值为空 $var = “”;

2变量的值为字符串0或者数字0  $var = 0 ; 或者$var =”0″

3变量的值为flase $var= flase;

4凡是为NULL的 都为空

5空数组  $arr =array();

6变量只定义不赋值$var;

这些全假

版权声明:本文为博主原创文章,未经博主允许不得转载。

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