Questions about double quotation marks, plus signs, and periods
Source: Internet
Author: User
I want to output $ a = 1 in double quotes, plus signs, and periods on the screen, so I wrote the following, but only the last one is correct. If you have two questions, the first one is why the first two outputs only numbers. What are the preceding & quot; $ a = & quot; and '$ a =? The second point is that the plus sign and the dot represent the double quotation marks, the plus sign, and the DOT sign in PHP.
I want to output $ a = 1 on the screen, so I wrote the following, but only the last one is correct.
I have two questions,
The first point is why the first two outputs only numbers. how does the former "$ a =" and '$ a =' handle them?
What exactly does the plus sign and the dot represent in PHP? Why is no error reported when the plus sign is used for the first two?
$ A = 1;
Echo "$ a =" + $ a; // error 2
Echo '$ a =' + $ a; // error 1
Echo "$ a =". $ a; // error 1 = 1
Echo '$ a ='. $ a; // correct $ a = 1
?>
I just got in touch with PHP and read the materials. I didn't find these two knowledge points. so I am going to ask for help. I hope you will be enlightened by the PHP experts. Thank you!
------ Solution --------------------
Variables are parsed in double quotes, but not in single quotes. . Is the string connector, + is the addition
------ Solution --------------------
+ Arithmetic operators
. String connector
------ Solution --------------------
Php will parse the string, "" will parse the internal escape or $, ''will only escape the internal \ ', regardless of other.
Echo "$ a =" + $ a; is because "" internal $, so it is changed to "1", "1" + 1 will be converted to an integer, get 2, "1 ". 1 is converted to a string, which is "11"
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.