String comparison function; comparison function; string comparison
php strnatcmp() function syntax
Function:Natural order method to compare strings
Syntax:strnatcmp(string1,string2)
Parameters :
Parameter | Description |
string1 | Required, specified The first string to compare. |
string2 | Must specify the second string to be compared. |
Description: Thestrnatcmp() function uses a "natural" algorithm to compare two strings. In natural arithmetic, 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. Note that this function is case-sensitive. If the two strings are equal, 0 is returned. If string1 is greater than string2, the returned value is greater than 0. If string1 is less than string2, the returned value is less than 0.
php strnatcmp() function example
"; echo strnatcmp("01hello world!","2hello world!"); ?>
Run instance»
Click the "Run instance" button to view the online instance
Output:
1 -1