开发者

PHP Concatenation using {} [duplicate]

This question already has answers here: 开发者_运维问答 Closed 11 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜