Use of PHP strnatcmp () function Summary _php tips

Source: Internet
Author: User

Definition and Usage
Definitions and usage
The strnatcmp () function compares two strings using a "natural" algorithm.
The strnatcmp () function is used to compare strings (case sensitive) with natural algorithms.

In a natural algorithm, the number 2 is less than the number 10. In computer sorting, the less than 2, because the "the" of "is" less than 2.
In the "Natural algorithms", 2:10 small. In the computer sequence, 10:2 is small, 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 string is 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

Copy Code code as follows:

STRNATCMP (STRING1,STRING2)
parameter Parameters Description Description
String1 Required. Specifies the "a" to compare
Necessary parameters. Specifies the first string object to participate in the comparison
string2 Required. Specifies the second string to compare
Necessary parameters. Specifies the second string object of a parameter comparison

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

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

Example
Case

Copy Code code as follows:

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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.