【发布时间】:2011-07-19 05:43:12
【问题描述】:
我仍然不知道它叫什么。喜欢:
$name = 'xxx';
echo "This is a string {$name}";
你把那个操作叫做什么?使用 {} 将变量连接到字符串中。
谢谢!
【问题讨论】:
标签: php
我仍然不知道它叫什么。喜欢:
$name = 'xxx';
echo "This is a string {$name}";
你把那个操作叫做什么?使用 {} 将变量连接到字符串中。
谢谢!
【问题讨论】:
标签: php
这不是串联;这是变量插值;请参阅 PHP 手册中的 Variable parsing 部分。
基本上,您可以使用以下两种语法中的任何一种:
echo "This is $variable";
或者:
echo "This is {$variable}";
在这两种情况下你会得到相同的结果——除了第二种允许更复杂的表达式。
连接将是这样的:
echo "This is my : " . $value;
变量$value 的内容使用concatenation operator . 连接到字符串。
【讨论】:
通常称为字符串或变量插值。
【讨论】:
How does {} affect a MySQL Query in PHP?
不要让问题本身把你抛到脑后——这个答案正是你想要的。
而且它不是串联的;这是连接:
$myvar = "This is a string ".$name; // <<< Notice I'm concatenating the variable
// using the . operator
【讨论】: