Comments are inserted in PHP to explain the code.
A Comments in PHP code is a line that is not executed as a part of the program.
This is specially useful when there are too many lines of code and the programmer can insert the comments not only to divide the page into logical sections to increase the readability of code.
But also to give information about the author of the code,the date on which the code was last edited etc.
There are two types of comments in PHP.
Single line comments in Php are start with two forward slashes( //
).
All text after //
will be ignored by PHP.
e.g // This is single line comments.
Code | |||||||
---|---|---|---|---|---|---|---|
<?php // This is single line comments echo "Hello World"; // Hello World $a=10;$b=20; echo $a+$b; // 30 ?> |
Type Url - https://localhost/php/single-line-comments.php
The multi line comments can be used to comments out large blocks of code.
Multi line comments in Php are begines with /*
and ends with */
.
All text between /*
*/
will be ignored by Php.
e.g
/* This is Multi line comments 1
Multi line comments 2 */
Code | |||||||
---|---|---|---|---|---|---|---|
<?php /* This is Multi line comments 1 Multi line comments 2 */ ?> |
Type Url - https://localhost/php/multiline-comments.php
Well there are several pattern to create comments in PHP given below.
Code | |||||||
---|---|---|---|---|---|---|---|
<?php # Comments Style 1 echo "Hello World"; # Hello World $a=10;$b=20; echo $a+$b; # 30 ?> <?php /* Comments Style 2 */ echo "Hello World"; /* Hello World */ $a=10;$b=20; echo $a+$b; /* 30 */ ?gt; <?php //=========================== Comments Style 3 =========================== // echo "Hello World"; //==== Hello World ===// $a=10;$b=20; echo $a+$b; //==== 30 ====// ?> <?php //----------------------- Comments Style 4 -----------------------// echo "Hello World"; //---- Hello World ----// $a=10;$b=20; echo $a+$b; //---- 30 ----// ?> <?php /** * This is multi line * Comments Style 5 * add more row for comments */ ?> |
Type Url - https://localhost/php/more-comments.php