loading...

Difference between Heredoc and Nowdoc 🤔

aaahmedaa profile image Ahmed Khaled MOhamed ・1 min read

Heredoc

heredoc will evaluate your variables and place them exactly where you placed in the string.
Example:


$name = "Ahmed Khaled";

$here_doc = <<<EOT
My name is "$name" and 
i love programming

EOT;

echo $here_doc;

Output:

My name is "Ahmed Khaled" and 
i love programming

Nowdoc

nowdoc will never evaluates your variables in the string

Example:


$name = "Ahmed Khaled";

$here_doc = <<<'EOT'
My name is "$name" and 
i love programming

EOT;

echo $here_doc;

Output:

My name is "$name" and 
i love programming

Discussion

pic
Editor guide