strcmp
PHP function
Edit on GitHub ✎
(PHP 4, PHP 5, PHP 7, PHP 8)
Binary safe string comparison
Description
strcmp(string $string1, string $string2): int
Note that this comparison is case sensitive. For case-insensitive comparison, see strcasecmp().
Note that this comparison is not locale aware. For locale aware comparison see strcoll() or Collator::compare
Parameters
string1The first string.
string2The second string.
Return Values Return
Changelog
| Version | Description |
|---|
Examples
strcmp() example
php
<?php
$var1 = "Hello";
$var2 = "hello";
if (strcmp($var1, $var2) !== 0) {
echo '$var1 is not equal to $var2 in a case sensitive string comparison';
}
?>See Also
Full string comparison
strcasecmp()Collator::comparestrcoll()
Partial string comparison
Similar / other string comparison