PHP Menu


Comments in PHP


In general, Comments are used in a programming language to describe the program or to hide the some part of code from the interpreter.

Comments in PHP can be used to explain any program code. It can also be used to hide the code as well.

Comment is not a part of the program, but it enhances the interactivity of the program and makes the program readable.

PHP supports two types of comments:

  • Single Line Comment
  • Multi Line Comment

1. Single Line Comment:

In case the developer wants to specify a single line comment, then the comment must start with " // "


format:
// This is single line comment

2. Multi Line Comment

In case of Multi lined comment, the comment must starts with /* and ends with */ i.e. /* .... */ .


format:
/* This 
    Is 
    Multiline comment */


Example: "commentdemo.php"


<html>

<head>
<title>Comments in PHP</title>
</head>
<body>
<h1>Comments in PHP</h1>
<?php
    
// echo prints something on screen
        
echo "This is My First PHP Example <br/>";

    
/* Comments are used to
        hide or describe the 
        code in php  */
        
echo ' This is an example to demonstrate comments in PHP ';
?>
</body>
</html>

Output :

image
Next Topic :Variables Declaration in PHP