What is single line comment in PHP? Explain with syntax.
A single line comment tells PHP to ignore everything on that line after the comment symbol. In PHP you can start it with // or #. You do not need to close it.
<?php
// This is a single line comment
# This is also a single line comment
echo "Hello World!"; // comment after the code
?>
Output:
Tutorials Class - Output Window
Hello World!
The comment ends at the end of the line (or at the closing ?> tag). For many lines use /* ... */. In PHP 8 the text #[ starts an attribute, so write a space after the hash. See all types of comments in PHP Comments.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Introduction |
| PHP Terminology |
| PHP Installation |
| PHP Syntax |
| PHP Comments |
| PHP exit() Function |
| Exercises & Assignments |
|---|
| Write a program to print “Hello World” using echo |
| Simple Tips for PHP Beginners |
| Experiment with Basic PHP Syntax Errors |
| Using phpinfo() – Display PHP Configuration & Modules |