empty values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shemeri
Forum Newbie
Posts: 1
Joined: Thu Oct 28, 2010 7:22 am

empty values

Post by shemeri »

Hello,

What are the output of these statements:

$var = 0
echo ( $var != "")

I would say it outputs true but it actually output false which means $var is "". But it is not, its integer 0

So, is "" same as integer 0 if not comparing by type using !==

Are these all empty values when comparing using $var != "":

$var = 0
$var = "0"
$var = array()
$var = ""
$var = null
$var false
mikecampbell
Forum Commoner
Posts: 38
Joined: Tue Oct 12, 2010 7:26 pm

Re: empty values

Post by mikecampbell »

Are these all empty values when comparing using $var != "":

$var = 0
$var = "0"
$var = array()
$var = ""
$var = null
$var false
See http://ca3.php.net/manual/en/language.o ... arison.php

The following are true:
0==""
0==null
""==null
0==false
""==false
false==null
0=="0"
false=="0"
array()==false
array()==null

The following are not true:
array()==0
array()=="0"
"0"==null
"0"==""
Post Reply