Strnatcmp () function-php Tutorial

Source: Internet
Author: User
The strnatcmp () function strnatcmp () is used to compare the numbers in a string by number.
$ Str1 = "mrsoft1 ";
$ Str2 = "MRSOFT2 ";
Echo strnatcmp ($ str1, $ str2 );
The expected result is-1, and the result is 1. what is the reason?


Reply to discussion (solution)

$ Str1 = "mrsoft1"; $ str2 = "MRSOFT2"; echo strnatcmp ($ str1, $ str2); // 1 because m is larger than M $ str1 = "mrsoft1 "; $ str2 = "mrsoft2"; echo strnatcmp ($ str1, $ str2); //-1 for $ str1 = "mrsoft11"; $ str2 = "mrsoft2 "; echo strnatcmp ($ str1, $ str2); // 1 This is the intention that 11 is greater than 2

Previously, I did not understand the function properly. I thought that I only compared the numbers in the string and ignored the ASCII value of the characters.
Thank you for your answers.

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.