DEV Community

Ahmed Khaled MOhamed
Ahmed Khaled MOhamed

Posted on

Difference between Heredoc and Nowdoc πŸ€”

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

Top comments (0)