开发者

diffrenece between $a=''; and $a=NULL; in php [duplicate]

This question already has answers here: 开发者_开发技巧 Closed 12 years ago.

Possible Duplicate:

In PHP, what is the differences between NULL and setting a string to equal 2 single quotes.

What does $a=''; indicates in php

and how $a=''; is different than $=NULL:


NULL is an unkown value, '' is an empty string.


do you mean $a = '' or $ a = ""

If so $a = "" or '' means that variable $a is being set equal to an empty string. In contrast $a = NULL means that variable $a is being set to a special PHP constant NULL which is effectively nothing. The major difference is that $a = '' sets $a as a string variable whereas $a = NULL doesn't. This tends to matter more in languages that require strict declaration of variable types.

See here for more info on NULL: http://php.net/manual/en/language.types.null.php


NULL indicates no value, it's like an unset variable. An empty string IS a value, and a variable containing an empty string IS defined.


<?php

$a = '';
echo '$a = \'\'';
var_dump( ($a == ''), ($a === ''), (is_null($a)) );

$a=null;
echo '$a = null';
var_dump( ($a == ''), ($a === ''), (is_null($a)) );

output:

$a = ''
boolean true
boolean true
boolean false
$a = null
boolean true
boolean false
boolean true
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜