In this part, we will learn about PHP comments. Comments are the main feature of any programming language. It helps the coder to explain the logic he has used in the program.
According to W3School:
The coder can explain the logic in simple words. We can also use the comment for testing our code. PHP ignore the data written within the comment and execute the remaining code.
There are two types of comment in PHP.
1. Single line comment
We can use this type of comment for applying comment on a single line. The comment within single line represent by // or # sign. In case we want to add comment on a single line within a program we will use the following syntax.
//store the value of variable a, b and c in d
#This also a single line comment
$d= $a + $b + $c;
//output the value of d
The line after “//” will not be visible to browser and that will be considered as comments. You guys can see the commented portion in green color.
2. Multi-line comment
We can also apply the comment to multiple lines within a program. The purpose of the multi-line comment is to explain the logic in detail. The syntax for commenting multiple lines start from <!– and end with –> sign. You can also use /* and */ for multiple lines comment. The data within these signs is considered as comment. For example, we want to add the comment on multiple lines within a program. We will use the following syntax.
/*Addition of two numbers in PHP is not that difficult job we can simply store two number in variables and then assign the values of these two variables to c, as given below. */
<!–Addition of two numbers in PHP is not that difficult job we can simply store two number in variables and then assign the values of these two variables to c, as given below. –>
echo $c = $a + $b;
Here is the output for this program.
Thus we can use the comment for multiple lines code.
When we use the comment within a program the area being commented turned into a different color in the text editor. For example, in the case of Sublime Text editor, the area of comment turned into gray color. Thus the user can see the commented part of the program easily.