Comparison between numbers and strings in PHP-php Tutorial

Source: Internet
Author: User
Comparison between numbers and strings in PHP comparison operators in PHP is a bit odd and error-prone. the comparison rules are listed as follows:

1. when comparing the two characters in size, is the ASCII code size of the two characters compared ?? This article is easy to understand.

2. when two strings are compared in size, they start from the first character and compare the corresponding ASCII size, as long as they start from a corresponding position, the current position character of one string is greater than the corresponding position character of the other string, that is, the size of the two strings, such as 'BA'> 'Az '?? This article is actually known to all.

The comparison between '10' and 'A' is the same. first, compare '1' and 'A' ASCII codes, which are larger than 'A.

3. when a number is compared with a string/character, the system first tries to convert the string/character to an integer/floating point type and then compare it, for example, if '12bsd' is converted to 12 and 'A' is converted to 0, you must note that the corresponding ASCII code value is not compared with the number.

In fact, the result of 'A' + 10 is also 10.

Which is easy to ignore: 0 returns true if it is compared with any string that cannot be converted to a number (operator =.

The following result is displayed:

1 var_dump ('000000' <'a'); // result: boolean true2 var_dump ('A' <1); // result: boolean true3 var_dump (1 <'123'); // result: boolean true

Your own instance:

 = 'Your Day');?>

Output result: boolean true

The Chinese character is first transcoded using Gbk or UTF-8. the Chinese character is converted to a letter at the underlying layer.

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.