Re: if (a == b) ...
| From: | Ernest E Vogelsinger | Date: | Thu, 30 Jan 2003 09:29:26 +0000 |
| Subject: | Re: if (a == b) ... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-133614@lists.php.net to get a copy of this message | ||
At 02:36 30.01.2003, Webapprentice said:
--------------------[snip]--------------------
>Hi,
>I have a conditional:
>if (a == b)
>
>a is the number 0, but b is a string "Friday August 22".
>
>The condition is evaluating as true, which is not what I want.
>What am I misunderstanding?
--------------------[snip]--------------------
PHP tries to "help" you - you can only compare data of the same type. So
PHP goes ahead and casts this for you, a string to int in this case.
If you compare it using "===" (typesafe comparison) you will get correct
results.
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/