What's this kind of syntax in PHP?

后端 未结 4 1925
孤城傲影
孤城傲影 2020-12-07 03:04
$test= <<

I have never see it before. What\'s it used for?

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 03:20

    Indeed, this is the Heredoc syntax.

    Just in case you are wondering what interest it can have vs the regular string delimiters:

    // These strings contain the same thing '"'"
    $s1 = '\'"\'"';
    $s2 = "'\"'\"";
    $s3 = <<

    No more quote escaping.
    A typical use case for me is when I need to store in a string some HTML code I have copy/pasted.

提交回复
热议问题