note 49740 added to function.strcmp
| From: | S dot Radovanovic at TriMM dot nl | Date: | Mon, 07 Feb 2005 14:36:21 +0000 |
| Subject: | note 49740 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84618@lists.php.net to get a copy of this message | ||
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).
----
Manual Page -- http://www.php.net/manual/en/function.strcmp.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49740
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49740&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49740&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49740&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49740&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49740&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49740&report=yes
Search -- http://master.php.net/manage/user-notes.php