PHP Comments

A comment in PHP code is used to understand the code which is not executed as a part of program.

PHP supports single line and multi line comments.

Used of PHP Comments

  • Understand your code for yours or others.
  • While working on big projects we need to define the comments to show the working of any functions and any part of code.

Types of PHP Comments

  • Single Line Comments
  • Multi Line Comments

PHP Single Line Comments

Syntax for single-line comments

<!DOCTYPE html>
<html>
<body>

<?php
// This is a single-line comment

# This is also a single-line comment
?>

</body>
</html>

PHP Multi Line Comments

Syntax for multiple-line comments

<!DOCTYPE html>
<html>
<body>

<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?>

</body>
</html>

We can use Comments to leave out parts of the code

<!DOCTYPE html>
<html>
<body>

<?php
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>

</body>
</html>

OUTPUT

10