Re: if (a == b) ...
| From: | Webapprentice | Date: | Thu, 30 Jan 2003 02:21:41 +0000 |
| Subject: | Re: if (a == b) ... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-133584@lists.php.net to get a copy of this message | ||
Cal,
Thanks for the suggestion. I looked up equality on www.php.net, and there are many comments about how == works.
I also found out === works too, or is that still lazy?
Thanks,
Stephen
Cal Evans wrote:
Stephen, "Friday August 22" evaluates to the number 0. (check the docs for intval()) Therefore the condition would be true. I stated in an earlier thread this week. It is bad for to allow PHP todo your conversions for you. At the least it's lazy, at the most it will cause unpredictable results. (as is your case below.) If you really MUST compare a string and a number, do an explicit cast first. if ($a==intval("Friday August 22")) or if (strval($a)=="Friday August 22") In both cases above, since we are explicitly casting, it is easy to predict the results and explain them. (In the above, the first should be true and the second should be false.) =C= * * Cal Evans * Stay plugged into your audience. * http://www.christianperformer.com *