How To Write PHP Comment in PHP codes with Examples

To become a good coder and make your code more meaningful you should always consider using PHP comments in your codes. Commenting on each line of code is the best practice to make to useful and easy to understand the purpose of each line.

What is PHP Comment

PHP comments are the lines which are not visible to your visitors. Comments are the useful part of your HTML and PHP codes. Many web developers use comments each time they want to understand the code types and the purpose of the codes.

You can put a single line or multiline of code to explain the functionality of the code. Commenting each section of the code helps developers in future to understand the functionality of the code and add more codes easily.

The main part of the comment is that they are not visible to the visitors. It can also be used to hide any line of code.

How to Add Single Line Comment using PHP comment

A double slash(//) can be used inside any PHP codes to add a single line of comment.

Example 1: Showing Single Line of PHP comment
This is the example showing Single line of PHP comment to make it meaningful and useful. A single line of comment is very easy and simple to add with just putting double slash before each line you to make it commented.

Output


Welcome to PHP Tutorial by Tutorialdeep

Add Multi-line Comments using PHP comment

We can add multiline of comments inside the PHP codes using /* at the start and */ at the end. They are very useful when you want to explain the functionality of the PHP codes. To show more functionality you must use multiline of comments to explain the full functionality of the PHP codes.

Example 2: Showing Multi-line of PHP comment
This is the example showing a single line of PHP comment to make it meaningful and useful. A single line of comment is very easy and simple to add with just putting a double slash before each line you to make it commented.

Output


Welcome to PHP Tutorial by Tutorialdeep

You must also read