RE: Re: Strange comparison behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



String "info" is converted to integer, which is 0...

a)
if("info" == "0")

b)
if("info" === 0)

c)
if("info" == (string)0)


Or use strcmp()

Cya...
Read a book "PHP for beginners"



-----Original Message-----
From: Bogdan Stancescu [mailto:gutza@xxxxxxxxxxx] 
Sent: Friday, May 13, 2005 5:13 AM
To: php-general@xxxxxxxxxxxxx
Subject:  Re: Strange comparison behaviour

You probably mis-typed something:

[bogdan@myserver ~]$ php
<?
if ("info" == 0) echo "is 0\n"; else echo "not 0\n";
?>
Content-type: text/html
X-Powered-By: PHP/4.3.11

is 0

Cheers,
Bogdan

Erwin Kerk wrote:
> Hi All,
> 
> Can anyone explain me why the following code:
> 
> if ("info" == 0) echo "is 0\n"; else echo "not 0\n";
> 
> Results in: not 0
> 
> 
> Whereas:
> 
> if ("inf" == 0) echo "is 0\n"; else echo "not 0\n";
> 
> Results in: is 0
> 
> 
> 
> Notice the difference: info in the first sample, inf in the second sample.
> 
> 
> The used PHP version is PHP 4.1.2 (CLI version)
> 
> 
> Erwin Kerk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux