PHP Comments

In PHP, comments are sections of code that are not executed when a program is run. It's only purpose to help the progarmmers to understand the code.

For example, when a developer is open a PHP file for the first time, so they can  easily understand the php code they are looking at. And It also helps the other programmers why we wrote this code.

In PHP, two ways of commenting

  1. Single Line 
  2. Multiple Lines

 

Single Line Comment: 

It is used to explain a single line of code. we can use two symbles for comment a single line of code ( # and // ). 

  • # - hash tag
  • // - double forward slashes

Example:

<!DOCTYPE html>
<html>
<body>

<?php

# This is my first comment

// This is another way to enter single line comment

?>

echo "Hello World"; //comment - why we are using this line

</body>
</html>

 

Multiple Lines Comments:

It is allow to comments multiples lines in PHP code.

Syntax:  comment start with  /* and end with */

Example: 

<!DOCTYPE html>
<html>
<body>

<?php
/*
This is the way of
comment multiple-lines
in PHP Code
*/

echo "Hello World";
?>

</body>
</html>