PHP Comments
A comment is a note inside code that PHP ignores. Comments help people read the code around them.
A line comment
The comment sits on its own line. The echo line below it still runs.
<?php
// Print a greeting
echo "Hello\n";A hash comment
This comment also sits on its own line. Only the echo line prints.
<?php
# Say hello again
echo "Hello again\n";A block comment around a statement
The block comment covers one whole statement. That statement does not run, so only the second line prints.
<?php
/* echo "Hidden line\n"; */
echo "Visible line\n";Example
<?php
// Print the plan for today
echo "Plan for today\n";
echo "Write one program\n"; // The second line of the planKey points
- Use // to start a line comment.
- A line comment runs to the end of its line.
- A hash sign also starts a line comment.
- Use /* to start a block comment and */ to end it.
- A block comment can hide a statement so it does not run.
In this example, a line comment sits above the first echo line. The first line prints Plan for today. A short comment sits after the second echo line, and that line prints Write one program.
Note
A comment is for readers, and it changes nothing in the output.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which pair starts and ends a block comment?