Solve the problem of PHP string comparison?

Source: Internet
Author: User
What are the rules for string size comparisons?
For example: "Ten", "10a", "a", "abc" How do they sort in ascending descending order?? Ask for rules!!


Reply to discussion (solution)

As far as I know, the rule of comparison between them is: The first letter of the ASCLL size comparison if the same is compared to the second one.

The string size is sorted according to the ASCII of the first character.

As far as I know, the rule of comparison between them is: The first letter of the ASCLL size comparison if the same is compared to the second one.
"Ten", "10a" How do these two compare?

Var_dump (STRNATCMP ("Ten", "10a"));

Int (-1)

means "10a" < "ten"

Reference to the 1 floor nowphp's reply: As far as I know, the rule of comparison between them is: first the ASCLL size comparison of the first letter if the same is compared to the second one.
"Ten", "10a" How do these two compare? And so on, if the second one is equal then the third one ... Nth one.

It seems to be a master AH study

Reference 3 Floor u010044579 's reply:
Reference to the 1 floor nowphp's reply: As far as I know, the rule of comparison between them is: first the ASCLL size comparison of the first letter if the same is compared to the second one.
"Ten", "10a" How do these two compare? And so on, if the second one is equal then the third one ... Nth one.
Still a little do not understand, look in detail: "10" third place No "10a" is a This how to compare?

No, and have you said which big?

What do you have to understand?
Do you understand the ASCII code?
10 Don't you think you should understand?
Do you know what ASCII a means in decimal? Rep 97

ASCII code 0 represents 48 in decimal
1 Rep 49
So 1
10 can be seen as 48 49
10a can be seen as 48 49 97
So the front 2 is the same, the third one is 97, one is none, which one do you mean which is small?

ASCII code 0 represents 48 in decimal
1 Rep 49
So 1
10 can be seen as 48 49
10a can be seen as 48 49 97
So the front 2 is the same, the third one is 97, one is none, which one do you mean which is small?
Okay, I got it, thanks.

  • 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.