PHP Comments Syntax

PHP Comments Syntax - single line comments and multiple line comments

PHP Comments are used to describe any line of code or program, But it can also be used to hide your code.

Not only this, it will help other developers to understand your code easily. And it also helps you because sometimes you forget why you wrote this code.


Like other languages, PHP also supports single line comments and multiple line comments.

And yes comments are not executed. That means you can’t see comments in browsers.

Single Line Comments

In PHP, there are two ways to use single line comments.

  • Using double forward slash (//)
  • Using the hash sign (#)

Example:

<?php
//This is a single line comment
#This is another single line comment
echo "You can't see comments in browsers";
?>
Browser Output
You can’t see comments in browsers

Multiple Line Comments

In PHP, Multiple Line Comments start with /* and ends with */

Example of PHP Multiple line Comments –

<?php
/* Multiple
Line
Comments */
echo "Hello World!";
?>
Browser Output
Hello World!

Next is – PHP Operators

Previous isPHP HereDoc, NowDoc, and HereDoc VS NowDoc

Posts Navigation


Leave a Reply

Your email address will not be published. Required fields are marked *