Summary of php strnatcmp of functions

  • 2020-11-25 07:10:12
  • OfStack

Definition and Usage
Definition and usage
The strnatcmp() function compares two strings using a "natural" algorithm.
The strnatcmp() function compares strings using a natural algorithm (case sensitive).

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 less than 10. In a computer sequence, 10 is less than 2 because the first number in "10" is "1", which is less than 2.

This function returns:
This function returns the following values:

•0 - if the two strings are equal
0 if the strings are equal
• < 0 - if string1 is less than string2
< 0 If string1 is less than string2
• > 0 - if string1 is greater than string2
> 0 If string1 is greater than string2
Syntax
grammar


strnatcmp(string1,string2) 
Parameter parameters Description description string1 Required. Specifies the first string to compare
Necessary parameters. Specifies the first string object to be compared string2 Required. Specifies the second string to compare
Necessary parameters. Specifies the second string object for the parameter comparison

Tips and Notes
Pay attention to the point
Note: The strnatcmp() is case-sensitive.
Note: the strnatcmp() function is case sensitive.

--------------------------------------------------------------------------------

Example
case


<?phpecho strnatcmp("2Hello world!","10Hello world!");echo "<br />";echo strnatcmp("10Hello world!","2Hello world!");?> 

The output of the code above will be:
The above code will output the following result: -1 1


Related articles: