How to write comments in PHP

Topic: HTML / CSS« Prev|Next »

Answer: Use the Syntax "// text" and "/* text */"

Comments are usually written within the block of PHP code to explain the functionality of the code. It will help you and others in the future to understand what you were trying to do with the PHP code. Comments will not be displayed in the output.

Single Line Comments

PHP single line comment begins with //, See the example below:

  • <?php
  •     echo "Hello World!"; // Output "Hello World!"
  • ?>

Multi-line Comments

PHP multi-line line comment begins with /*, and ends with */.

  • <?php
  •     /* The following line of code
  •        will output the "Hello World!" message */
  •     echo "Hello World!";
  • ?>

Related FAQ

Here are some more FAQ related to this topic:


Your Feedback:


We would love to hear from you! Please say something.