So we will now discuss about comments, let's consider a scenario where you have written a huge amount of code with different classes, functions, id's, etc. then how would you remember the work of each and every block of code? or suppose you have sent the code to someone else then how would that person will understand the code written by you? You have to write some hints throughout your code to be able to understand it even after some time later or for the person whom you are sending the code. These hints will be written in the form of comments.
Yes, a comment is that part of your program which the Compiler or the Parser ignores. You can write anything in a comment even a piece of code but that will be completely ignored by the PHP Parser. So you can make your code more readable and understandable to yourself and to others by writing hints or explanation of code in the form of comments.
In this tutorial, we will go through different ways of writing a comment in PHP.
PHP supports two types of comment:
Single Line Comments and
Multi Line Comments.
Let's go through these one by one:
These are short comments and are
used wherever short explanations are required.
For Single Line Comments you just have to add double slash
(//) or hash
(#) sign and now whatever you will write to the right side of these signs ,till you hit enter, it will be considered as a comment by the Parser and will be ignored.
If you want to add multiple lines as a comment without going through the hassle of adding double slash(//) or hash(#) signs in every line then you should use Multi Line Comments.
These comments will allow you to create a block, inside which you can write multiple lines of comments as required.
To add the Multi Line Comments, you need to begin and end the line with
(/* Comment goes here */).