Comment is that part of the code that is not parsed by the parser. The main objective of the comment is to provide necessary notes to the programmer. It helps in understanding the code better. Every language has a different way of storing a comment. In PHP, the comments are stored in a manner similar to that of C++. Let’s see a single line comment in a PHP script.
<?php //echo “We are checking a comment.”; echo “We are checking a comment.”; ?>
The output will be:
We are checking a comment.
Why is there only a single line in the output when we have given the echo command twice. The reason is that the first statement is a comment. Any statement written after double slash (//) will not be parsed by the parser and hence, you can put absolutely any notes there for your convenience. But now suppose, we want to add multiple lines of comment instead of a single line comment. It would be very tedious to put “//” at the beginning of each line. This problem has been simplified. Multiple line comments are handled in the following manner:
<?php /*This is a multiple line comment. You can as many lines as you want here. They will not affect the PHP script.*/ echo “We just learnt multiline comment.”; ?>
In the above code, we have used “/*” to mark the beginning of the comment and “*/” to mark the end of the comment. And here’s the output to the above script:
We just learnt multiline comment.