是否有 function/way 自动在输出之间添加空格?

Is there a function/way to automatically add spaces between output?

在 PHP 中,我正在呼应字符串和变量的混合。我希望能够在每个片段之间自动添加一个 space,这样我就不必每次都添加一个 ' '。

示例:

echo "This is my" . $string . ".";

这将输出"This is mystring"。是否有一些功能可以将回声包装在其中自动放置 space ?谢谢

不,你应该自己做

echo "This is my " . $string . "."; 

或更简单:

echo "This is my $string."; 

php 字符串的一些简单阅读:What is the difference between single-quoted and double-quoted strings in PHP?

一个自定义函数可以自动添加空格和echo:

$four_five = 'four five';
echospace('one', 'two', 'three', $four_five, 'six');
// one two three four five six

function echospace () {
    echo join(' ', func_get_args());
}