您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

判断php变量是不是定义,是否为空

2024/4/25 11:48:06发布5次查看
判断php变量是否定义,是否为空
isset() 【1】
returns?true?if?var?exists and has value other than?null,?false?otherwise.
输入可以是多个变量,只有所有的变量为真的时候,返回真
empty()【2】
returns?false?if?var?has a non-empty and non-zero value.
the following things are considered to be empty:
(an empty string)0 (0 as an integer)0 (0 as a string)nullfalsearray() (an empty array)var $var; (a variable declared, but without a value in a class)输入只能是一个变量
is_null() 【3】
returns?true?if?var?is?null?,?false?otherwise.
?
?
a variable is considered to be?null?if:
it has been assigned the constant?null.
it has not been set to any value yet.
it has been?unset(). ? ?
?
?
使用 php 函数对变量?$x?进行比较表达式gettype()empty()is_null()isset()if($x) boolean
$x = ; string true false true false
$x = null; null true true false false
var $x; null true true false false
$x?is undefined null true true false false
$x = array(); array true false true false
$x = false; boolean true false true false
$x = true; boolean false false true true
$x = 1; integer false false true true
$x = 42; integer false false true true
$x = 0; integer true false true false
$x = -1; integer false false true true
$x = 1; string false false true true
$x = 0; string true false true false
$x = -1; string false false true true
$x = php; string false false true true
$x = true; string false false true true
$x = false; string false false true true
?
(上表没有找到原始来源,谁知道请告诉我)
如果变量是一个object该如何呢?
?
表达式gettype()empty()is_null()isset()if($x) boolean
$x = new object()? object false false true true
?
参考:
【1】http://php.net/manual/en/function.isset.php
【2】http://www.php.net/manual/en/function.empty.php
【3】http://www.php.net/manual/en/function.is-null.php
?
?
http://blog.csdn.net/autofei/archive/2010/05/24/5619004.aspx
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录