Search code examples
phpstringoperatorsheredoc

In PHP, what does "<<<" represent?


For example:

$sql = <<<MySQL_QUERY

Solution

  • That's heredoc syntax. You start a heredoc string by putting <<< plus a token of your choice, and terminate it by putting only the token (and nothing else!) on a new line. As a convenience, there is one exception: you are allowed to add a single semicolon after the end delimiter.

    Example:

    echo <<<HEREDOC
    This is a heredoc string.
    
    Newlines and everything else is preserved.
    HEREDOC;