0

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:

0

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Thanks a lot for your reply,But if i do like $a=''; $b=NULL; if($a==$b) echo 'variable Matches !'; else echo 'No Match !'; that will give true.so can u give me some realistic example
0

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.

Comments

0
<?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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.