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"