开发者

Is it possible to concatenate heredoc string in PHP..?

With normal PHP string you can do this:

$str = "Hello ";
$str .= "world";
$str .= "bla bla bla";
$str .= "bla bla bla...";

But can you do the same with heredoc string..?

$str = <<<EOD
Hello 
world开发者_如何学C
EOD;

$str .= <<<EOD
bla bla bla";
bla bla bla...";
EOD;


Of course. Why wouldn't you be able to?

Heredocs evaluate to a string, so this is perfectly acceptable.


Yes you can. Heredoc is part of expressions, so you can even do this:

$s = 'abc' . <<<EOD
def
EOD
. 'ghi';

Be careful with the end-of-data marker though: it should be the only thing on a line.


Yes you can.

A heredoc is equivalent to double quoted string without the double quotes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜