Re: wierd if statments
| From: | Andreas Pour | Date: | Thu, 26 Oct 2000 22:51:24 +0000 |
| Subject: | Re: wierd if statments | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22224@lists.php.net to get a copy of this message | ||
Chris Lee wrote:
>
> <?
> $tmp1 = 0;
> $tmp2 = "all";
>
> if ($tmp1 == $tmp2)
> echo "TRUE<br>\n";
> else
> echo "FLASE<br>\n";
> ?>
>
> Whats going on here, this returns TRUE !!!
What do you expect when you compare an int and a string ;-)? Actually,
0 is a wierd value in PHP, and the empty string is also unpredictable,
especially when you do casting (there is some implicit type casting
going on in the comparison). Try to compare things of the same type:
if ("" . $tmp1 == $tmp2)
...
Ciao,
Andreas Pour
http://www.kde.com/ : Everything KDE
http://apps.kde.com/: The Latest in KDE Applications