Comments in PHP are similar to the comments used in HTML.
A comment in PHP code is not a part of the PHP program. Its only purpose is to be read by someone who is editing the code.
Read Also: PHP Syntax
This article describes us how to use the PHP comments in code.
- PHP comment is an essential part of the PHP code.
- PHP comment makes the code trouble-free to read and maintain.
- Comments in PHP are similar to the comments used in HTML.
- PHP comment syntax always begins with a unique character(// or # or /*).
- PHP comments used to describe any code so that the developer can quickly understand the system.
- It can also apply to hide the code for temporary purposes.
PHP Supports Two Types of Comment
- Single-Line Comment
- Multi-Line Comment
PHP single-line comment is useful to comment on just one line of code.
There two ways to use the single-line comment in PHP.
- // (C++ Style single-Line Comment)
- # (Unix Shell Style Single-Line Comment)
<html> <body> <?php //echo “C++ Style single-Line Comment”; #echo “Unix Shell Style Single-Line Comment”; echo “Welcome Suman!”; ?> </body> </html>
Notice that a couple of echo statements are not giving results because we commented them out with a single line comment.
Like HTML code, the PHP multiple line comment is useful to comment large blocks of code.
PHP multi-line comment begins with /* and ends with */.
<?php /* Anything placed within comment will not be executed */ echo "Welcome Suman"; ?>
Read More: PHP Variables
PHP comment is an essential part of the PHP code, and it makes the code easier to read and maintain.
Use single-line comments for quick notes about a tricky part in your code and use multiple line comments when you need to describe something in higher depth than a simple letter.
I hope now you have a real understanding of PHP comments.