PHP supports ‘C’, ‘C++’ and Perl style comments.
Generally comments are use for programmer to understand the code.
The comments are not printed in output.
comments are also used to hide any code.
PHP supports one-line and multi-line comments.
For example:
PHP one-line comment
A one-line comment is start with //.
Usually one-line comment can be use to the end of the line.
Means the immediate next line code will be printed.
They are generally used for short explanation or notes.
1 2 3 4 5 |
<?php echo "This is example of comments"; //This is one-line comment ?> |
Output:
1 |
This is example of comments |
In PHP, we can comment multiple lines. These multiple lines comment need to be closed within /* */.
Multi-line comment are generally used to provide detailed explanations when necessary.
1 2 3 4 5 6 7 8 |
<?php /* ----------------------------------------------------------- This is a example of multi-line comment -------------------------------------------------------------*/ echo "This is example of comments"; ?> |
Output:
1 |
This is example of comments |