PHP comments


Comments in PHP code are lines that are not executed as part of the program. Its only purpose is to be read by the person looking at the code.

  • Single-line PHP comments are great for quick notes before a block of code or to explain a single line of code.
  • To leave a one-line comment, type two slashes (//) followed by the comment text.

Single Line Comment

Example
<html>
<body>
<?php
//single-line comment
# single-line comment
?>
</body>
</html>

Multi Line Comment

Example
<html>
<body>
<?php
/*
 Multiple-lines comment
*/
?>
</body>
</html>

Output

Welcome
Hello World!

Using Comments in Program

Example
<html>
<body>
<?php
$a = 10;
//$b = 20;
echo $a;
?>
</body>
</html>

Output

10

Prev Next