For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > May 2007 > Re: [PHP-DB] weird comparsion









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] weird comparsion
Mike van Hoof

2007-05-03, 7:57 am

http://nl3.php.net/manual/en/langua....comparison.php

try using === (3x =) for comparison

- Mike

OKi98 schreef:
> Hello,
>
> Why does anything compared to 0 return true?
>
> I know it might seem to be a bit off-topic, but for me it is important
> for detecting if NULL value in table has been changed (for example
> NULL is changed to 0).
>
> if ("foo"==0) echo("foo equals to 0");
>
> OKi98
>

OKi98

2007-05-03, 7:57 am

Mike van Hoof wrote:

> http://nl3.php.net/manual/en/langua....comparison.php
>
> try using === (3x =) for comparison
>
> - Mike
>
> OKi98 schreef:
>
>
>
> __________ Informace od NOD32 2235 (20070502) __________
>
> Tato zprava byla proverena antivirovym systemem NOD32.
> http://www.nod32.cz
>
>
>

I know about identity operator (===) but with == operator 0 is false and
"foo" is true, try this:

$foo=0;
$bar="bar";
if ($foo) echo("$foo is true, ");
else echo("$foo is false, ");
if ($bar) echo("$bar is true, ");
else echo("$bar is false, ");
if ($foo==$bar) echo("$foo==$bar");

returns "0 is false, bar is true, 0==$bar"

OKi98
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com