Compare two strings (case-sensitive):
<?php
echo strcmp("Hello world!","Hello world!");
?>
Try it Yourself »
The strcmp() function compares two strings.
Note: The strcmp() function is binary-safe and case-sensitive.
Tip: This function is similar to the strncmp() function, with the difference that you can specify the number of characters from each string to be used in the comparison with strncmp().
strcmp(
string1,string2)
Parameter | Description |
---|---|
string1 | Required. Specifies the first string to compare |
string2 | Required. Specifies the second string to compare |
Return Value: | This function returns:
|
---|---|
PHP Version: | 4+ |
Compare two strings (case-sensitive = Hello and hELLo will not output the same):
<?php
echo strcmp("Hello","Hello");
echo "<br>";
echo strcmp("Hello","hELLo");
?>
Try it Yourself »
Different return values:
<?php
echo strcmp("Hello world!","Hello world!"); // the two strings are equal
echo strcmp("Hello world!","Hello"); // string1 is greater than string2
echo strcmp("Hello world!","Hello world! Hello!"); // string1 is less than string2
?>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!