php The strcmp function is used to compare two strings. Its syntax is strcmp(string1,string2). The parameter string1 is required and refers to the first string to be compared; string2 is required and refers to the second string to be compared. String.
#php How to use strcmp function?
Definition and usage
strcmp() function compares two strings.
Note: The strcmp() function is binary safe and case-sensitive.
Tip: This function is similar to the strncmp() function, except that with strncmp() you can specify the number of characters for each string to be compared.
Syntax
strcmp(string1,string2)
Parameters
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to be compared.
Return value:
This function returns:
0 - if the two strings are equal
<0 - if string1 is less than string2
>0 - if string1 is greater than string2
PHP version: 4
Example 1
Compare two String (case sensitive, Hello and hELLo output are different):
"; echo strcmp("Hello","hELLo"); ?>
Output:
0 -1
Example 2
Different return values:
Output:
0 7 -7
Example 3
Compare two strings (case sensitive):
Output:
0
The above is the detailed content of How to use php strcmp function?. For more information, please follow other related articles on the PHP Chinese website!