What is the difference between "<<<SQL SQL;" and using quotes for a statement [duplicate]

StackOverflow https://stackoverflow.com/questions/19953674

  •  30-07-2022
  •  | 
  •  

Frage

Could anyone provide some sort of documentation on the differences and or benefits of using

$sql = <<<SQL
      SELECT COUNT(ParentGUID) 
      FROM siteobjects  
SQL;

Instead of using just using.

  $sql = "SELECT COUNT(ParentGUID) 
      FROM siteobjects";

Struggling to find any information on this due to searching for "<<

War es hilfreich?

Lösung

The first one uses HEREDOC syntax. It's useful when you're working with multi-line strings and to avoid quoting problems. To solve the search issue, you can use a programming search engine that doesn't ignore special characters (like SymbolHound).

Andere Tipps

There's no difference except for the fact that the HEREDOC would have white spaces in the start (because of tabulation).

That's PHP Heredocs syntax (http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc). I prefer heredocs over simple strings because almost any IDE recognize the syntax, and it's more readable, but both options are possible.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top