PHP Concatenation using {} [duplicate]
Possible Duplicate:
curly braces in string
I still don't know what it's called. Like:
$name = 'xxx';
echo "This is a string {$name}";
What do you call that operation? Concatenating a variable using {} in to a string.
Thanks!
This is not concatenation ; this is variable interpolation ; see the Variable parsing section, in the PHP manual.
Basically, you can use any of the two following syntaxes :
echo "This is $variable";
Or :
echo "This is {$variable}";
And you'll get the same result in both cases -- except the second one allows for more complex expressions.
Concatenation would be something like this :
echo "This is my : " . $value;
Where the content of the variable $value
is concatenated to the string, using the concatenation operator .
.
It's often called string or variable interpolation.
How does {} affect a MySQL Query in PHP?
Don't let the question itself throw you - this answer gives you exactly what you are looking for.
And it's not concatenating; this is concatenating:
$myvar = "This is a string ".$name; // <<< Notice I'm concatenating the variable
// using the . operator
精彩评论