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

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

  •  30-07-2022
  •  | 
  •  

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 "<<

有帮助吗?

解决方案

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).

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top