In PHP, the string "1" equals the string "+1" unless you do a strict comparison (===).
echo ("1" == "+1") ? "equals" : "not equals"; // result: "equals" I'd prefer not to do a strict comparison, because the string "1" might be provided as an integer 1 in this case. I cannot do intval() to distinguish them because both return as 1, and I cannot do is_numeric() to distinguish them because both return true.
So, two questions please:
Is there any way to differentiate between these other than to convert the input to strings via
strval()and use strict comparison?Is this a bug or intended behavior in PHP? The reason doesn't seem mathematical ("2" does not equal "1+1" for instance, although "2" does equal "+2"). I'm curious as to the reasoning behind this.
((string)"1" === "+1")or((string) intval("1") === "+1")?