独学而无友,则孤陋而寡闻!
分类:
2010-05-16 22:51:00
One thing to note in comparison with ==
When we make a comparison with == php automaticly converts strings to
integers when either side of the comparison is an integer, f.e.:
$value = 0;
if($value == "submit") {
echo "Let's submit";
}
?>
Above would be succesful, since "submit" is converted to an
integer (eq 0) and the equation is would return true; (that's why (1 ==
"1submit") would also return true)
That's why we should use strcmp or === (checks type also), for string
comparisons.
So my conclusion is that when comparing string, you'd better not make
use of == (use strmp or === instead). For integer comparisons the ==
equation can be usefull, since our values will always be casted to an
integer (1 == "1" returns true).