i

PHP Tutorial

PHP Comments

Comments are the set of lines that need not be executed. A comment in PHP code is not executed as the part of the program and is for understanding purpose only. Like if someone is reading the code, he should be able to understand the motive of writing those set of commands.

>Need of comments

· To let people understand your code or statements.

  • Help you recall the developing purpose as developers might forget the code purpose after a year or two and comments can help in that time.

>Single Line Comments

There are two ways to mark the statement as a single line comment. One is //, and the other is #.

For example –

// It is a single line comment in PHP.

# This is also a single line comment in PHP.

>Multi-Line Comments

The syntax for using multi-line comments is /* */, and you can use this syntax in between the script also to comment some portion of the statement.

For example –

/* I do not want to display these lines

So, I have created a multiple-lines comment block

That will not give output

*/

Another example when we use multi-line comment inside a statement the output will ignore the comment and display the result.

 $x = 5 /* + 15 */ + 5;

 echo $x;

 ?>

The output of this php script will be 10.