问题
For variable $x
we can concatenate it to a string in many ways, one of them is like the following:
$x = "Hello";
echo "I say {$x} to all of you.";
// The output should be: I say Hello to all of you.
However, If I tried to do something like this with a function, it will fail:
$x = "Hello";
echo "I say {strtolower($x)} to all of you.";
// The output should be: I say {strtolower(Hello)} to all of you.
If there is a synonym way just like used for the variable, I will be appreciated to know it. In other words, I don't want to split the main string and I don't want to use sprinf
.
回答1:
You can concatenate with .
operator:
echo "I say " . strtolower($x) . " to all of you.";
Or just :
echo "I say ", strtolower($x), " to all of you.";
来源:https://stackoverflow.com/questions/27494038/concatenate-php-function-output-to-a-string-like-variables