判断php变量是不是定义,是否为空
Jun 13, 2016 pm 01:04 PM
判断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)
- 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 = ""; | 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

인기 기사

인기 기사

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Java의 String.replace() 함수를 사용하여 문자열의 문자(문자열)를 바꿉니다.
