pTutorial

New way to learn PHP

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

  1. Comments are ignored by the browser, but useful for us and as well as other programmers.
  2. It is good programming practice to use the comment.
  3. The Comment does not show on the browser.

PHP supports two-way of commenting

  1. Single line comment
  2. Multiple line comment

PHP Single line comment

Single line comment has two types

  1. Using "#"
  2. 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"); ?>

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

pTutorial

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"; ?>

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.


QUOTES OF THE DAY

Beauty's tears are lovelies than her smiles.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER