判断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
相关文档:
index.php文件第一行就是包含了
include_once('./common.php');
文件所以先对common.php文件解析
<?php
/*
[UCenter Home] (C) 2007-2008 Comsenz Inc.
$Id: common.php 10981 2009-01-14 03:05:20Z liguode $
*/
//定义一个常量,用来在其他页面中,防止被恶意用户直接调用其他PHP文件。
@def ......
a:
为什么要使用缓存技术?理由很简单:提高效率。在程序开发中,获取信息的方式主要是查询数据库,除此以外,也可能是通过Web Services或者别的某种方法,无论哪种方法,在大量的并发访问面前,它们都可能成为效率的瓶颈,为了解决这些问题,人们提出了很多解决方案,其中一 些是利用优化软件(如:APC,Eaccelerator, ......
最近做了几个小型的项目,比较简单,只是需要细心,都可以完成,主要是对MVC模式的熟练应用,对WEB类开发还是很有帮助的。
刚开始的第一个小项目,用来练手,然后我全部是流程化的编程。代码也就400行左右。结果我的导师,觉得代码结构不清晰,不容易
维护,需要修改。需要我采用OO类的编程方式进行改写。我以前写PHP,几 ......
今天想使用这一句php来判断一个文件是否存在: echo is_file('/var/downloads/donkey/incoming/[当地球停止转动].The.Day.The.Earth.Stood.Still.DVDRip.XviD-DMT.avi')?"true":"false";
echo is_file('/var/downloads/donkey/incoming/[当地球停止转动].The.Day.The.Earth.Stood.Still.DVDRip.XviD-DMT.avi')?"t ......