对于变量$x
,我们可以通过多种方式将其连接到字符串,其中一个如下:
$x = "Hello";
echo "I say {$x} to all of you.";
// The output should be: I say Hello to all of you.
但是,如果我尝试使用某个功能执行此类操作,则会失败:
$x = "Hello";
echo "I say {strtolower($x)} to all of you.";
// The output should be: I say {strtolower(Hello)} to all of you.
如果存在与变量一样的同义词方式,我将不胜感激。换句话说,我不想拆分主字符串,我不想使用sprinf
。
答案 0 :(得分:4)
您可以与.
运算符连接:
echo "I say " . strtolower($x) . " to all of you.";
或者只是:
echo "I say ", strtolower($x), " to all of you.";