Comments in PHP

phpIn any programming or scripting language, comments are very important.  While writing your code, you may write several lines of code with a lot of custom functions to make your code processing faster.  But if your fellow team member look over that code, it will be hard for him to figure out what that code actually does because everyone has got a unique style of coding.  Even if you look over your code file after a week or a month duration, it will be hard for you to figure out too.  In such a scenario, a comment can save your a lot of time.  In PHP, there are 2 types of comments, single-line and multi-line comments.

Single-line comment starts with 2 forward slashes (//).  It is helpful in case of providing small info about your code.

Multi-line comment starts with /* and ends with */.  Any text written in between will be treated as comment and it is helpful in case of providing detailed information about your code.

Since both of them are PHP comments, they should be placed within your PHP code only. An example of single-line and multi-line comments is given below.

<?php
 
 //This is a single-line comment.
echo "Single-Line Comment. ";


/* 
   This is an example of
   Multi-line comment.
*/   
 echo "Multi-Line Comment.";
?>