Home > Article > Backend Development > How to use php strcmp function
php The strcmp function is used for binary safe string comparison. Its syntax is strcmp(string1,string2). The parameter string1 must be the first string to be compared, and string2 must be the second string to be compared. String.
#php How to use strcmp function?
Function: Compare two strings (case sensitive)
Syntax:
strcmp(string1,string2)
Parameters:
string1 Required, specified to be compared the first string.
string2 Required, specifies the second string to be compared.
Description: The strcmp() function compares two strings. The strcmp() function is binary-safe and case-sensitive. If the two strings are equal, 0 is output. If string1 is less than string2, the output value is less than 0. If string1 is greater than string2, the output value is greater than 0.
php strcmp() function usage example 1:
<?php $i = "Hello world"; $j = "HELLO WORLD"; echo strcmp($i,$j); ?>
Output:
1
php strcmp() function usage example 2:
<?php echo strcmp("str1", "str2"); ?>
Output:
-1
This article is an introduction to the PHP strcmp function. I hope it will be helpful to friends in need!
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!