Troubleshooting of point number-php Tutorial

Source: Internet
Author: User
Point number: PHPcodeecho1 + 5.1. why is the error echo1 + 5.1 returned when writing this statement? this statement can be executed by echo1 + 5. (1); a bracket is added, but the solution is --------------------. when it is adjacent to a number, it is recognized as a decimal number and a decimal number smaller than 1 can omit the Starting 0, such as 0.1. 1 is legal, so the question of + 5.1
PHP code
  Echo '1 + 5 = '. 1; // why is the error echo '1 + 5 = 'reported when writing this code '. 1; // This sentence can be echo '1 + 5 = '. (1); // A bracket is added to the outside, but the line is displayed.


------ Solution --------------------
When it is adjacent to a number, it is recognized as a decimal number.
The first 0 can be omitted if the number is smaller than 1. for example, 0.1 is valid when it is written as. 1.

Therefore, '1 + 5'. 1 is parsed into two adjacent constants. if there is no operator between them, an error is reported.

Similarly, 1. "abc" also reports an error.
------ Solution --------------------
When it is adjacent to a number, it is recognized as a decimal number, as said on the second floor.
Echo '1 + 5 = '. 1; // This sentence can be executed .. In PHP, a connector is used to connect strings.

------ Solution --------------------
As hengyu654 said, when "." is directly connected to a number, it is not processed as a string concatenation, but as a decimal point.
As follows:
PHP code
Echo "thr ". "ee"; // output string "three" echo "twe ". "lve"; // output string "twelve" echo 1. 2; // output string "12" echo 1.2; // output number 1.2 echo 1 .. 2; // output string "10.2"

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.