QUIZGUM

Coding Class

Quizgum : here-doc

using here doc

Use here-doc when declaring a value in a variable, regardless of the line of code.

here doc how to use

  1. $string = <<<EOL
  2. string string blah blah
  3. string string blah blah
  4. string string blah blah
  5. EOL;

In the code above, you entered EOL starting with <<< before entering the value to assign.
This means that you start assigning values ​​regardless of the line of code.
And once you're done, enter EOL one more time.
Here is an example of using the here doc to assign a value to a variable and output it.

  1. <?php
  2. $hereDoc = <<<EOL
  3. Hello?<br>
  4. Good to see you?<br>
  5. My homepage letting me use really thank you ! <br>
  6. Go !!<br>
  7. Not giving up let <br>
  8. Let's live and die nicely!<br>
  9. EOL;
  10.  
  11. echo $hereDoc;
  12. ?>

Here is the resulting image

You can also put variables. Like this:

  1. <?php
  2. $hello = "안녕하세요?";
  3. $hereDoc = <<<EOL
  4. Hello?<br>
  5. Good to see you?<br>
  6. My homepage letting me use really thank you ! <br>
  7. Go !!<br>
  8. Not giving up let <br>
  9. Let's live and die nicely!<br>
  10. EOL;
  11.  
  12. echo $hereDoc;
  13. ?>

Here is the resulting image.

The EOL used in the here doc is called the Termination ID, and there are EOT, END, and EOT in addition to EOL. Using different things will not work and should start and end with the same thing.