Questions about but double quotes and plus and dot numbers
Source: Internet
Author: User
Questions about but double quotes and plus and dot numbers
I want to output $a = 1 on the screen, so I wrote the following, but only the last one is right.
There are two points to ask,
1th is the first two why only output the number, the front of the "$a =" and "$a =" is how to deal with it?
2nd, what exactly does the plus sign and dot number represent in PHP? Why didn't the two front signs have an error?
$a = 1;
echo "$a =" + $a; Error 2
echo ' $a = ' + $a; Error 1
echo "$a =". $a; Fatal error 1=1
echo ' $a = '. $a; Correct $a=1
?>
Just contact PHP, read the information, did not find the two points of knowledge, so come up for help, but also hope that you PHP talent. Thanks, man.
------Solution--------------------
Double quotes resolve variables, and single quotes do not: Number is a string connector, + is the plus
------Solution--------------------
+ Arithmetic Operators
. String connector
------Solution--------------------
PHP parses the string, "" will resolve the internal escape or $, "will only escape the internal \ ', and no other."
echo "$a =" + $a; It is because of the "" internal $, so was replaced by "1", "1" + 1 will turn into integers, 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.