PHP character-to-integer

Source: Internet
Author: User

1 $arr Array (0=>1, "AA" =>2, 3, 4); 2  3 foreach ($arras$key= +$val) {4     Print ($key$val); 5 }

Output results: 5534

Why

When two values in PHP are logically judged, if the type of two values is inconsistent PHP automatically converts the value on the right to the left type.

And then make a judgment. So the "AA" transformation is equal to 0, and naturally equals the left 0.

Character-type conversion shaping

Example:

Var_dump ((int) (' B '));                     // 0    Var_dump ((int) (' very good '));       // 0    Var_dump ((int) (' 132very '));             //  the    Var_dump ((int) (' ver1323 '));            // 0

You can draw a rule: start with a valid number and go to a valid number. Convert to 0, starting with a non-valid number;

PHP character-to-integer

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.