PHP Comments


In PHP code, a comment is a line that isn't executed as part of the program. Its is intended just for anybody who looks at the code to read it.


Comments can be used to

Make your code understandable to others. Recall what you did - Most programmers have had the experience of returning to their own work a year or two later and having to re-learn what they done. Comments might serve as a reminder of your thoughts while you created the code.

PHP supports several ways of commenting.

Example 1 :- 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>

Example 2 :- Syntax for multiple-line comments:-

<!DOCTYPE html>
<html>
<body>

<?php

/*
This is a multiple-lines comment block
that spans over multiple
lines
*/

?>
</body>
</html>

Example 3 :- Using 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

You can also search for these topics, comments in php, types of comments in php, php comments example, use of php comments, php comment line, php comment system, php comment standards, Single line comment, multiple line comment.