PHP Comment
Comment in PHP
Comments play very important role at time of development. A Comment in PHP code is short note that PHP engine ignores.
PHP comment is used to provide the short description of our code to the other developer or for own understanding.
Some important about PHP comment
- Comments are ignored by the browser, but useful for us and as well as other programmers.
- It is good programming practice to use the comment.
- The Comment does not show on the browser.
PHP supports two-way of commenting
- Single line comment
- Multiple line comment
PHP Single line comment
Single line comment has two types
- Using "#"
- Using "//"
PHP Comment Syntax
// this is comment line # this is comment line
PHP Single Line Comment Example
<?php echo"hello welcome to php". "
"; //Comment line echo "Hello". "
"; // this is my Second output statement echo date("Y/m/d") . "
"; # Display current_date echo date("Y.m.d") . "
"; // in different format echo date("Y-m-d"); ?>
- Example
- Run
In the above example, line number 5, 9, 13 and 17 are comments line that will not display on the Web Browser.
PHP Single line comment
<?php echo "pTutorial"; //echo "pTutorial"; ?>
OUTPUT
The second statement of the above example is a comment so that will not execute.
PHP Multiple Line Comment
/* this is a multiple line comment. It will not execute. */
Multiple line comment example
<?php /*echo"hello welcome to php". "
"; echo "Hello". "
"; echo date("Y/m/d") . "
"; echo date("Y.m.d") . "
"; */ echo date("Y-m-d"); echo "Only two echo will be executed"; ?>
- Example
- Run
You can make comment, any statement, function, variable etc by using /* */ or // or #.
In the above example from line 3 to 9 are not executed and rest of the statements will execute properly.
The comment will not be displayed when script is being executed.