The function prototype for strcmp () is as follows ()
int strcmp (string str1,string str2)
The function requires two parameter strings for comparison, and if the two strings are equal, the function returns 0, if the dictionary order str1 after str2 (greater than STR2) returns a positive number, otherwise, returns a negative number, which is case-sensitive.
The function strcasecmp () is the same as strcmp () except for case insensitive.
function strnatcmp () is case-sensitive and differs from strcmp ()
The strnatcmp () function uses a "natural" algorithm to compare two of strings. In natural algorithms, the number "2" is less than the number "10". In the computer sort, "2" is greater than "10", because "2" is greater than the first number of "10".
The function returns:
0-If two strings are equal
<0-if string1 is less than string2
>0-if string1 is greater than string2
Example:
<?phpecho strnatcmp ("2Hello world!", "10Hello world!"); echo "<br/>"; Echo strnatcmp ("10Hello world!", "2Hello world!"); >
Output:
-11
strcmp () comparison functions and strcasecmp () and strnatcmp ()