In this tutorial, We will learn How to add Comments in PHP with an example.
A comment is a line of text which is not read and executed as part of the program. It is used to add notes of the source code.
When writing code you may have some complex logic that is confusing, this is a perfect opportunity to include some comments in the code that will explain what is going on.
Not only, it will help you to remember the code later, but if someone else views your code, they will also be able to understand the working of code and saves time.
In PHP there are two types of comments
Single line Comments in PHP
In PHP you can define single line comment in two ways –
Both do the same work.
These types of comments are great for commenting out single lines of code and writing small notes.
If you want to comment on more than 1 line then you need to add it to each line.
<?php // This is a single line PHP comment # This is a single line PHP comment
Multi-line Comments in PHP
Although a single line comment is quite useful, it can sometimes be burdensome to use when disabling long segments of code or inserting long-winded comments. For these large comments, you can use PHP multi-line comment that begins with /* and ends with */.
/* Comment text */
<?php /* This is multi-line PHP comment block */
Be First to Comment