Is integer zero null?

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
incubator136
Forum Newbie
Posts: 2
Joined: Wed Dec 31, 2008 3:42 am

Is integer zero null?

Post by incubator136 »

Hi,
I wondered by checking the output of the following php script.

Code: Select all

 
<?php
$test = 0;
if($test != '')
    echo  ' Not Null';
else
    echo  ' Null';
?>
 
Instead of "Not Null" as I expected, I got the output as "Null".
The script works if I use any value except 0 or if I use quotes around 0.
The integer 0 is considered as null unlike other integers.
I am bit confused, can anyone help me out?
Thanks in advance …
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Is integer zero null?

Post by requinix »

incubator136
Forum Newbie
Posts: 2
Joined: Wed Dec 31, 2008 3:42 am

Re: Is integer zero null?

Post by incubator136 »

Thanks tasairis!
Post Reply