Re: How can an elephant count for nothing?

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

 



> While PHP has a lot of nice features, it also has some traps which I am forever falling
> into. One which I find particularly hard to understand is how mixed mode comparisons work.
> For instance
>
> $string =  'elephant';
> If($string == 0) returns true;
> If($string != 0) returns false;
> If($string === 0) returns false;
>
> I know that in this case I should use 'If($string == '')', but I still manage to forget.
> Can anyone explain clearly why comparing a string with zero gives this apparently
> anomalous result?
>

when comparing string with integer, the interpreter first converts
string into an integer before comparison takes place.

Virgil
http://www.jampmark.com

-- 
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