note 25703 added to function.strcmp
| From: | madsen at sjovedyr dot dk | Date: | Wed, 02 Oct 2002 16:59:33 +0000 |
| Subject: | note 25703 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37556@lists.php.net to get a copy of this message | ||
It's definitely worth noting that the return-values of strcmp() when used for i.e.
password-checking is the oposite of that of the ==-operator.
I.e.:
$pw1 = "yeah";
$pw2 = "yeah";
if (strcmp($pw1, $pw2)) { // This returns false.
// $pw1 and $pw2 are NOT the same.
} else {
// $pw1 and $pw2 are the same.
}
Where the use of the == operator would give us.:
if ($pw1==$pw2) { // This returns true.
// $pw1 and $pw2 are the same.
} else {
// $pw1 and $pw2 are NOT the same.
}
Additionally, to check if $pw1 and $pw2 are of the same type you can use the === operator.
--
http://www.php.net/manual/en/function.strcmp.php
http://master.php.net/manage/user-notes.php?action=edit+25703
http://master.php.net/manage/user-notes.php?action=delete+25703
http://master.php.net/manage/user-notes.php?action=reject+25703