Comments in PHP

Comments in PHP

Comment is just a piece of information that is not executed but it just provides some information to the reader of the code. Comments help you understand the code. PHP supports both single line comment and multi line comment.

Comments Usage in PHP

Comments are very helpful and it's always suggested to write comments with your code. Comments can tell you about the purpose of a particular piece of code. Comments act as Note to any programmer who reads it or works on it.

Single Line Comments in PHP

To write a single line comment, type 2 forward slashes like this ( // ), everything after these two slashes on the same line will be ignored and won't be executed.

<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
?>
</body>
</html>

You can also make a single line comment using pound sign or number sign ( # ) in PHP.

<!DOCTYPE html>
<html>
<body>
<?php
# This is also a single-line comment
?>
</body>
</html>

Multi Line Comments in PHP

Multi line comments begin with ( /* ) and ends with ( */ ). They can last up to as much lines as you want.

<!DOCTYPE html>
<html>
<body>
<?php
/*
This is a multiple-lines comment block
that can go 
up to many lines.
*/
?>
</body>
</html>

You can also comment out piece of code and it won't be executed. This trick can also help you out in recognizing the part of code which has errors.