What is the difference between Heredoc and NowDoc in PHP?

Heredoc and NowDoc are two ways to define multi-line strings in PHP. The main difference between them is that Heredoc allows for variable interpolation, while NowDoc treats everything within the delimiters as a literal string. To use Heredoc, you need to start the delimiter with <<< followed by a unique identifier and end with the same identifier. NowDoc uses single quotes instead of double quotes for delimiters.

// Using Heredoc for multi-line string with variable interpolation
$name = &quot;John&quot;;
$heredocString = &lt;&lt;&lt;EOD
Hello, $name!
This is a Heredoc string.
EOD;

// Using NowDoc for multi-line string without variable interpolation
$nowdocString = &lt;&lt;&lt;&#039;EOD&#039;
Hello, $name!
This is a NowDoc string.
EOD;