> You are right, "0" didn't show as a value.
>
> But his two lines still don't need typecasting, they both work:
> http://24.234.52.166
I don't mean to pick on you, but no, you are wrong. And I am only doing
this because so many people get confused on this point and I always see
questions related to it.
His lines were:
$qty = "0" ; if ($qty != "test") print "qty is not test";
$qty = 0 ; if ($qty != "test") print "qty is not test";
So his two conditions can be simplified to:
if("0"!="test") echo 1;
if(0!="test") echo 2;
Try this code yourself, or his original code if you want. Only the first
condition is met and you will only see it print 1.
When you are comparing an integer to a string, the string will get
converted to its integer representation. The integer representation of
"test" is 0. So the second condition becomes:
if(0!=0)
which is obviously false. Therefore if you cast it:
if((string)0!="test")
You are again comparing a string to a string and PHP will not try to
convert "test" to an integer.
-Rasmus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]