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
EOD;
$str .= <<<EOD
bla bla bla";
bla bla bla...";
EOD;
There are two string operators. The first is the concatenation operator ('. '), which returns the concatenation of its right and left arguments.
The heredoc syntax is a way to declare a string variable. The heredoc syntax takes at least three lines of your code and uses the special character <<< at the beginning.
In computing, a here document (here-document, here-text, heredoc, hereis, here-string or here-script) is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file.
Heredocs and nowdocs are the easiest and cleanest ways in php to use and format multiline strings. The only difference between a heredoc and a nowdoc is that a heredoc performs string interpolation, turning your variables into the string they represent, while a nowdoc does not.
Of course. Why wouldn't you be able to?
Heredocs evaluate to a string, so this is perfectly acceptable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With