How to Add Comment in PHP

Comment is a line of text which is not read and executed as part of the program.

It is used to add notes to the source code or stop some block of code from execution.

When writing a long script it is very helpful by adding comments on each step about what the code does.

If some other using your code or updating then it is easier for the user to understand the working of code and saves the time.

In PHP there are two types of comments  –

  1. Single line
  2. Multi-line

How to Add Comment in PHP


Contents

  1. Single line
  2. Multi-line
  3. Conclusion

 

1. Single line

You can define single line comment in two ways –

  • //
  • #

Both do the same work.

If you want to comment more than 1 line then you need to add it to each line.

Syntax –

// Comment text

# Comment text

Example 

<?php

// This is a single line comment

# This is a single line comment

 

2. Multi-line

With /* */ multi-line comment is added.

Syntax –

/*

Comment text

*/

Example

<?php

/*
This is multi-line
comment block
*/

 

3. Conclusion

With the comment, you can add quick notes on the code and use it for debugging the program.

You can use any of the 3 types of comment methods in your program.

Related Post

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *