In PHP, comments are used to add explanatory or descriptive text within the code that is not meant to be executed by the PHP interpreter. Comment lines in PHP are used to provide documentation, explanations, or reminders for developers who read and maintain the code. They are not executed as part of the code and do not affect the functionality of the PHP script.
There are two types of comment lines in PHP:
These comments begin with two forward slashes (//) and continue until the end of the line. For example:
<?php //This is a single-line Comment ?>
Anything written after // will not be executed and is only meant for developers to read.
These comments start with /* and end with */ and can span across multiple lines. For example:
<?php /* This is a multi-line Comment */ ?>
Multi-line comments are useful for adding longer explanations or documentation within the code.
Comments in PHP are commonly used for the following purposes:
Using comment lines in PHP can greatly enhance code clarity, maintainability, and collaboration among developers, making it easier to understand, modify, and debug PHP scripts.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <?php //This is a single-line Comment echo "<h1>Welcome to PHP Tutorial By Tutor Joes</h1>"; /* This is a multi-line Comment */ ?> </body> </html>
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions