Comments are the part of the PHP code , that is not executed. It’s a note note to the person who is reading the code.
Usage of comments
- Let other programmers / developers understand what is written and what the code does .
- Comments can help you ! It will remind you what you’ve written if you you come back after several days or years.
Types of comments
- Single line commnts
- Block comments
Example of comments
We can use
# for single line comments and
/* */ for block comments. Look at the example below.
<?php # example of single line comment echo "Hello world"; // this is also single line comment /* This is an example of multi-line comment */ ?>
See the output below. Comments have no effect in the output.
But do not try to nest comments.
<?php /* this is commented */ but this don't */ ?>