Comment in computer programming is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters. It is a non-executable line. comment is used to write the description for your own understanding.Browser doesn’t read the comments.There are two types of comments used in
There are two types of comments used in PhP
1. Single line comments: Single line comment used for short explanations. Declaration of Single line comment are two types Either Begin with (#) or backslash (//)
<?php # This is the single line comment # This is the next line comment // This is also a single line comment. ?>
In the above example, First and second line comments begin with the hash (#) and the third one begins with (//). If we check the output of the given example. Browser show blank page. Because comments are always non-executable.
Another Example of Single line Comment
<?php $str= "welcome "; //$str. =" student"; echo $str; ?>
In the above example, we declare a variable to store the String (“welcome”). In the second line, we concatenate string (“student”) with the Previous string (“welcome”). In the third line, we check the output. It shows Welcome Only because the second line statement has already specified a comment statement. So it can’t take the string (“student”) as a declaration.
2. Multi-lines comments: Multi lines comments used to comment multiple lines. Here we can give comments in bulk. The bulk comments are enclosed within (/*…..*/)
<?php /* This is a comment with multiline Developer : Study Warehouse view : Multiline Comments Demo */ ?>
All lines which are defined in PHP environmental are Multiline comments. it is non-executable because it encloses with Multiline comments statement.
Another example of Multi-line comments
<?php /* $str = "welcome "; $str.= "users "; */ echo "Hello user how are you? "; ?>
Output: Hello user how are you?