Posted by Paul Wellner Bou on 10/02/02 11:18
Hi,
Chris Hope wrote:
> mrbog wrote:
>> if (0 == 'asdfasdf' ) echo 'WHAT THE FUCK??????????';
>
> I posted something about this the other day.
>
> When comparing a string with a number the string is first evaluated as a
> number, which in the case of the above is example is 0. So in effect
> you are comparing 0 with 0.
Sorry, this is not correct. The string and the number will be casted to
a boolean value. And a non empty string is definitly true. 0 will be
casted to false.
$ php -r 'if (0 == "asdf") echo "true\n"; else echo "false\n";'
true
> if(0 === "asdfasdf")
>
> which will evaluate the condition as false. Note I'm using === here and
> not ==
>
> === compares the types strictly whereas == does not.
This is correct.
$ php -r 'if (0 === "asdf") echo "true\n"; else echo "false\n";'
false
Regards
Paul.
Navigation:
[Reply to this message]
|