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 or stop some block of code from execution.
When writing a long script it is very helpful by adding comments on each step about what the code does.
If some other using your code or updating then it is easier for the user to understand the working of code and it saves time.
In PHP there are two types of comments –
- Single line Comment
- Multi-line Comment
Contents
1. Single line Comment
You can define single line comment in two ways –
- //
- #
Both do the same work.
If you want to comment more than 1 line then you need to add it to each line.
Syntax –
// Comment text # Comment text
Example
<?php // This is a single line comment # This is a single line comment
2. Multi-line Comment
With /* */ multi-line comment is added.
Syntax –
/* Comment text */
Example
<?php /* This is multi-line comment block */
3. Conclusion
With the comment, you can add quick notes on the code and use it for debugging the program.
You can use any of the 3 types of comment methods in your program.
If you found this tutorial helpful then don't forget to share.