How to Write Comment in PHP | Comment In PHP

Comment In PHP

In this video, we will learn about the comment in PHP so let's get started,

What is Comment?

A comment in PHP code is a line that is not executable as a part of the program its only purpose is to read by someone who is looking at the code.

Comments Can be used to 

let others understand your Code what is mean by for example if you write some Complex Code without putting any comments and any other person will try to understand that code it may be difficult for him to understand but if you put an Appropriate comment to that code than any other developer can understand easily.

Remind yourself of what you did, sometimes it may happen to you also that putting a comment in code is a good practice for doing code.

Types of Comment

A comment is a two type of comment first one is a single line and the second one is a multiline Let look at those comments, the single-line comment starts With // or # in PHP. Any text between // or # and end of the line is ignored by PHP. As we have seen Comments are not executable by the PHP.

let's see the multiline comment, multiline comment starts with /* and ends with */ any text between lies /* and */ will be ignored by PHP.

Let's look at the example to better understand Open your code editor And here is a file which will create in the Previous video to make sure your xampp server is running or the Wamp server is running.

let me write basic code for HTML in Here I am writing Comment in PHP

<title>comment in PHP</title>

ok so first I am writing h2 tag for HTML within that I am writing PHP start and end tag, now Here I am writing all this comment whatever I needed for the program, for example, I write echo “Hello Elkick” Ok Now, I want to write single line comment for this line so I will just right // look at the color of that line this is the single-line comment or else I can write # This is the single-line comment, I am writing here echo how are you elkick ok so this is how single-line comment works, I am writing here <br> for printing in next line.

<h2>
    <?php

          // This is The Single Line Comment
          echo "Hello Elkick!!<br>";

          #This is the Single Line Comment
          echo "How Are you Elkick!<br>";
    ?>
 </h2>
let’s open your browser and type localhost within htdocs I have folder elkick PHP within that I have file Index.php so I write index no need to write index.php when you write index.php files so just hit enter and you can see your it will print hello Elkick and how are you Elkick you can see the comment part will be not executed here by the PHP ok.

so let's move on to the multiline comment Let me put first put <br> here and for example if I write echo hello world  semicolon if I want to write a multiline comment here what I did it take /* */ within this I am writing any kind of line statement whatever you want so I am writing here this is multiline comment and this will print hello world on screen and it's amazing ok 
 /* This is Multiline Comment
    And This will Print Hello World On Screen
    And it's Amazing. */
    echo "Hello World";
Note:- Write This block Inside the PHP tag

let's go to the browser and hit refresh look at you will get hello world without any kind of multiline comment so this is how you can write in the line comment this is how you can write a multiline comment here is an example of which will just discuss.


index.php

 <!DOCTYPE html>
<html lang="en">
<head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>comment in PHP</title>
</head>
<body>
      <h2>
            <?php

                  // This is The Single Line Comment
                  echo "Hello Elkick!!<br>";

                  #This is the Single Line Comment
                  echo "How Are you Elkick!<br>";



                  /* This is Multiline Comment
                  And This will Print Hello World On Screen
                  And it's Amazing. */
                  echo "Hello World";



            ?>
      </h2>
 </body>
 </html>




    Comment below if you have any queries related to the above tutorial for Comment In PHP.


Post a Comment

0 Comments