Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

For example:

$sql = <<<MySQL_QUERY 
like image 984
Chrish Avatar asked Sep 13 '10 11:09

Chrish


People also ask

What does this symbol mean in PHP?

This operator allows for simpler three-way comparison between left-hand and right-hand operands. The operator results in an integer expression of: 0 when both operands are equal. Less than 0 when the left-hand operand is less than the right-hand operand.

What does a $$$ mean in PHP?

The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, float, etc. The $$x (double dollar) is a reference variable that stores the value which can be accessed by using the $ symbol before the $x value. These are called variable variables in PHP.

What is heredoc and Nowdoc in PHP?

Heredoc and Nowdoc are two methods for defining a string. A third and fourth way to delimit strings are the Heredoc and Nowdoc; Heredoc processes $variable and special character but Nowdoc does not processes a variable and special characters.


2 Answers

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; 
like image 177
tdammers Avatar answered Oct 15 '22 09:10

tdammers


It is the start of a string that uses the HEREDOC syntax.

A third way to delimit strings is the heredoc syntax: <<<.

After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

like image 27
Pekka Avatar answered Oct 15 '22 10:10

Pekka