PHP Concatenation using {}

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 . .


它通常被称为字符串或变量插值。


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
链接地址: http://www.djcxy.com/p/59530.html

上一篇: PHP回声替换为一个变量

下一篇: PHP连接使用{}