In this tutorial, you will learn about the different types of commenting systems available in PHP.
PHP comments are commenting systems used in PHP code to understand the code in the future by the other developer or by himself. That Means, comments are used for a better understanding of PHP source code.
Comments are not displayed in the output. It is ignored by the PHP engine.
There are two types of comments in PHP.
- Single Line Comment.
- Multiline Comments.
PHP comments are similar to the C, C++, and Unix shell type(Perl Style) comments.
1) PHP Single Line Comment
PHP Single Line Comments can be defined in two ways.
- # (Unix Shell style single line comment)
- // (C, C++ style single line comment)
<?php # this is Unix Shell style single line comment // this is C, C++ style single line comment echo "PHP single line comments!"; ?>
In the above example, you can see that single line comments are ignored by the PHP engine and not shown in the output.
2) PHP Multiline comments
PHP supports multiline comments. PHP multiline comments are achieved by enclosing all the lines within /* */. Below is an example of PHP multiline comments.
<?php /* Anything placed here will not be displayed on the browser; */ echo "PHP multi line comment"; ?>