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 Comments
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is single line comment in PHP? Explain with syntax.