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

本文详细介绍了PHP中isset(), empty(), is_null()和gettype()这四个常用函数的作用、用法示例,并特别探讨了在对象上下文中的行为。通过实例演示,帮助理解变量状态的判断和类型检查。
摘要由CSDN通过智能技术生成

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)

NULL

FALSE

array() (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 = "";stringTRUEFALSETRUEFALSE

$x = null;NULLTRUETRUEFALSEFALSE

var $x;NULLTRUETRUEFALSEFALSE

$x?is undefinedNULLTRUETRUEFALSEFALSE

$x = array();arrayTRUEFALSETRUEFALSE

$x = false;booleanTRUEFALSETRUEFALSE

$x = true;booleanFALSEFALSETRUETRUE

$x = 1;integerFALSEFALSETRUETRUE

$x = 42;integerFALSEFALSETRUETRUE

$x = 0;integerTRUEFALSETRUEFALSE

$x = -1;integerFALSEFALSETRUETRUE

$x = "1";stringFALSEFALSETRUETRUE

$x = "0";stringTRUEFALSETRUEFALSE

$x = "-1";stringFALSEFALSETRUETRUE

$x = "php";stringFALSEFALSETRUETRUE

$x = "true";stringFALSEFALSETRUETRUE

$x = "false";stringFALSEFALSETRUETRUE

?

(上表没有找到原始来源,谁知道请告诉我)

如果变量是一个object该如何呢?

?表达式gettype()empty()is_null()isset()if($x) Boolean

$x = new object()?objectFALSEFALSETRUETRUE

?

参考:

【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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值