Comments in PHP

Comment

Comments are written in between the codes to remember the purpose of that code.

Comments are not executed with the code. It is written solely for the reader to read and understand why the code was written.

As developers keep working different projects and later when they look back at their old code, it's hard to remember what idea the developer had while writing that peice of code. So to overcome this, we use comments.

Now coming to the types of comments in PHP

We have 2 types of comments :

1.Single line comment

2.Multi-line comment

Single line comments :

Single line comments can be written using the "//".

Example:

<?php

echo "hello";

//this is a single line comment

?>

Single line comments can also be written using "#".

Example:

<?php

echo "hello";

//this is a single line comment

#this is another single line comment

?>

Multi-line comments :

In php, Multi-line comments can be written using "/*" and "*/

Example:

<?php

echo "hello";

/*
this is a 
multi-line comment
in php 
*/

?>

Comments can also be written in between a line of code.

Example:

<?php

echo "hello";

$answer = $a + /* sum of a and b*/ $b;
echo $answer;

?>