note 27568 deleted from language.operators.comparison by sniper
| From: | sniper@php.net | Date: | Mon, 13 Oct 2003 00:17:40 +0000 |
| Subject: | note 27568 deleted from language.operators.comparison by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58441@lists.php.net to get a copy of this message | ||
Note Submitter: AJCartmell@ricardo.com
----
To clarify on 'numerical' string equality comparisons, for example when testing progam
version numbers where "two.three" is not the same as "two.thirty":
$a = "2.3";
$b = "2.30";
$a == $b => true (unexpected)
(string)$a == (string)$b => true (unexpected)
To fix this problem append a space to the ends of each string, or use the === operator (which
doesn't have the implicit casting to numbers that the == operator does)
"$a " == "$b " => false
$a.' ' == $b.' ' => false
$a === $b => false
The first is the slowest, the second 10% faster, the last seven times faster than the second.