Concept Flow - Comments in PHP
Start PHP code
Read line
Is line a comment?
Yes→Ignore line, no output
No
Execute line
More lines?
Yes→Read next line
No
End PHP code
PHP reads each line, ignores comment lines, and executes only the code lines.
<?php // This is a single-line comment # Another single-line comment /* This is a multi-line comment */ echo "Hello"; // Prints Hello ?>
| Step | Line Content | Is Comment? | Action | Output |
|---|---|---|---|---|
| 1 | <?php | No | Start PHP code | |
| 2 | // This is a single-line comment | Yes | Ignore line | |
| 3 | # Another single-line comment | Yes | Ignore line | |
| 4 | /* This is a | Yes | Ignore line | |
| 5 | multi-line comment */ | Yes | Ignore line | |
| 6 | echo "Hello"; // Prints Hello | No | Execute echo statement | Hello |
| 7 | ?> | No | End PHP code |
| Variable | Start | After Step 6 | Final |
|---|---|---|---|
| Output | "" | "Hello" | "Hello" |
PHP comments start with // or # for single-line, and /* */ for multi-line. Comments are ignored by PHP and do not affect output. Code after comments runs normally. Use comments to explain code without changing behavior.