This article mainly summarizes the usage of strnatcmp () function in php. If you need it, you can refer to it for help.
This article mainly summarizes the usage of strnatcmp () function in php. If you need it, you can refer to it for help.
Definition and Usage
Definition and usage
The strnatcmp () function compares two strings using a "natural" algorithm.
The strnatcmp () function is used to compare strings (case sensitive) with natural arithmetic operations ).
In a natural algorithm, the number 2 is less than the number 10. In computer sorting, 10 is less than 2, because the first number in "10" is less than 2.
In the "natural algorithm", 2 is smaller than 10. In the computer sequence, 10 is smaller than 2, because the first digit in "10" is "1" and it is smaller than 2.
This function returns:
This function returns the following values:
• 0-if the two strings are equal
0-if the string is equal
• <0-if string1 is less than string2
<0-If string1 is smaller than string2
•> 0-if string1 is greater than string2
> 0-If string1 is greater than string2
Syntax
Syntax
The Code is as follows:
Strnatcmp (string1, string2)
Parameter Description
String1Required. Specifies the first string to compare
Required parameter. Specifies the first string object involved in the comparison
String2Required. Specifies the second string to compare
Required parameter. Specifies the second string object for Parameter comparison
Tips and Notes
Notes
Note: The strnatcmp () is case-sensitive.
Note: The strnatcmp () function is case sensitive.
--------------------------------------------------------------------------------
Example
Case
The Code is as follows:
"; Echo strnatcmp (" 10 Hello world! "," 2 Hello world! ");?>
The output of the code above will be:
The above code will output the following results:-1 1