Using Comments in PHP – Learn PHP in 7 Days – Day #3

Comments are those line which are not executed by the compiler. Comments in PHP are similar to comment in C or C++ or JAVA. Comments are the best way to explain the logic of an application. PHP supports both single line a multiple line comments. Let use see how we can add them.

Single Line Comments

There are 2 ways of writing single line comments in PHP. One is the classy old way of using double backslash (\\) and the other one is using the hash (#) symbol. Here’s the example

<?php
echo "Comment Test!"; // Lets test the commenting feature
echo "The other way"; # echo "nothing";
// echo "Does this line print?";
# echo "You can sever see this";
?>

4-comments-1

That’s out output. I hope you got the meaning of comments

Multiple Line Comments

When single lines are not sufficient enough to accommodate you comments and you need to put a # symbol on each line, then multi line comments come to your rescue. Using multi line comments is as simple as single line comments. Just start a multi line comment with /* (front slash followed by an asterisk) and stuff everything and then close it with */ (asterisk followed by a front slash).

The example is pretty self explanatory, so lets hit with an example and see how it works

<?php
/* this is a multiline comment
You can use as many lines you want
Just make sure you close it properly */
echo "a multi line comment";
?>

As expected, you get the following output for the above code

4-comments-2

So I think that was all about using comments in PHP.

Related posts:

  1. PHP Syntax, Variables, Echo Statement – Learn PHP in 7 Days – Day #1
  2. Using Operators in PHP – Learn PHP in 7 Days – Day #2
  3. Learn PHP in 7 Days
  4. How to display Posts with most Comments
  5. MS DOS Tutorials – How to Create, Delete, Change, Rename Directory and Files


The author is a small business owner himself specialising in Web Development. He runs Insight Studios which offers specialized Web Development, SEO Services and PPC Management for Small Business and SME thus ensuring growth and prosperity using the power of social media.

Share This Post

Related Articles

One Response to “Using Comments in PHP – Learn PHP in 7 Days – Day #3”

  1. [...] #2 – Using Operators in PHP Day #3 – Using Comments in PHP Day #4 – Using Conditional Statements in PHP Day #5 – Using Loops in PHP Day #6 [...]

Leave a Reply

© 2012 MyGeekPal. All rights reserved. Site Admin · Entries RSS · Comments RSS
Designed by Insight Studios