How to Comment Code in PHP

Comment code is important part of any kind of programming language.

PHP code comments are the same as HTML code comments.

Comment code is only visible at the part of programming side while run the program the comment code invisible at output side.

While complex programming we have more code at programmer side and many programmer can work on one project so we need to define the code logic with header comment code so other programmer can easily understood the code.

There are two way we can comment code in PHP.

  • Single Line Comments
  • Multi Lines Comments

Single Line Comments in PHP

In single line comments we can comment only single line using the comment expression “//” and “#”.

Here, Example of single line comments:

<html>
<head>
</head>
<body>

<?php

// First comment code line

// Second comment code line

# Third line comment
?>

</body>
</html>

Multi Lines Comments in PHP

Here is the example of Multi lines comment code in PHP.

<html>
<head>
</head>
<body>

<?php

/* All code are commented with multilines comments
First comment code line
Second comment code line */

?>

</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

9 + 3 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">